WIP #341 Logout
This commit is contained in:
parent
67d7bb45f5
commit
20d3498bfd
@ -35,6 +35,10 @@ class EntityCollection {
|
||||
});
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_allEntities.clear();
|
||||
}
|
||||
|
||||
Entity _createEntityInstance(rawEntityData) {
|
||||
switch (rawEntityData["entity_id"].split(".")[0]) {
|
||||
case 'sun': {
|
||||
|
@ -242,7 +242,7 @@ class HomeAssistant {
|
||||
_sendSubscribe();
|
||||
} else if (data["type"] == "auth_invalid") {
|
||||
Logger.d("[Received] <== ${data.toString()}");
|
||||
_logout();
|
||||
logout();
|
||||
_completeConnecting({"errorCode": 62, "errorMessage": "${data["message"]}"});
|
||||
} else if (data["type"] == "result") {
|
||||
Logger.d("[Received] <== id: ${data['id']}, success: ${data['success']}");
|
||||
@ -262,10 +262,11 @@ class HomeAssistant {
|
||||
}
|
||||
}
|
||||
|
||||
void _logout() {
|
||||
Future logout() async {
|
||||
_token = null;
|
||||
_tempToken = null;
|
||||
SharedPreferences.getInstance().then((prefs) => prefs.remove("hassio-token"));
|
||||
//TODO proper clear
|
||||
await SharedPreferences.getInstance().then((prefs) => prefs.remove("hassio-token"));
|
||||
}
|
||||
|
||||
void _sendSubscribe() {
|
||||
@ -283,19 +284,19 @@ class HomeAssistant {
|
||||
}
|
||||
|
||||
Future _getLongLivedToken() async {
|
||||
await _sendSocketMessage(type: "auth/long_lived_access_token", additionalData: {"client_name": "HA Client app", "lifespan": 365}).then((data) {
|
||||
await _sendSocketMessage(type: "auth/long_lived_access_token", additionalData: {"client_name": "HA Client app ${DateTime.now().millisecondsSinceEpoch}", "lifespan": 365}).then((data) {
|
||||
if (data['success']) {
|
||||
Logger.d("Got long-lived token: ${data['result']}");
|
||||
_token = data['result'];
|
||||
_tempToken = null;
|
||||
SharedPreferences.getInstance().then((prefs) => prefs.setString("hassio-token", _token));
|
||||
} else {
|
||||
_logout();
|
||||
logout();
|
||||
Logger.e("Error getting long-lived token: ${data['error'].toString()}");
|
||||
}
|
||||
}).catchError((e) {
|
||||
Logger.e("Error getting long-lived token: ${e.toString()}");
|
||||
_logout();
|
||||
logout();
|
||||
});
|
||||
}
|
||||
|
||||
@ -361,7 +362,7 @@ class HomeAssistant {
|
||||
Logger.d("Firing event to reload UI");
|
||||
eventBus.fire(ReloadUIEvent());
|
||||
}).catchError((e) {
|
||||
_logout();
|
||||
logout();
|
||||
disconnect();
|
||||
flutterWebviewPlugin.close();
|
||||
_completeFetching({"errorCode": 61, "errorMessage": "Error getting temp token"});
|
||||
@ -377,7 +378,7 @@ class HomeAssistant {
|
||||
_hassioChannel.sink.add('{"type": "auth","access_token": "$_tempToken"}');
|
||||
} else {
|
||||
Logger.e("General login error");
|
||||
_logout();
|
||||
logout();
|
||||
disconnect();
|
||||
_completeFetching({"errorCode": 61, "errorMessage": "General login error"});
|
||||
}
|
||||
|
@ -164,7 +164,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
||||
StreamSubscription _showErrorSubscription;
|
||||
StreamSubscription _startAuthSubscription;
|
||||
StreamSubscription _reloadUISubscription;
|
||||
bool _accountMenuExpanded = false;
|
||||
int _previousViewCount;
|
||||
//final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
|
||||
|
||||
@ -353,11 +352,11 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
||||
UserAccountsDrawerHeader(
|
||||
accountName: Text(widget.homeAssistant.userName),
|
||||
accountEmail: Text(widget.homeAssistant.hostname ?? "Not configured"),
|
||||
onDetailsPressed: () {
|
||||
/*onDetailsPressed: () {
|
||||
setState(() {
|
||||
_accountMenuExpanded = !_accountMenuExpanded;
|
||||
});
|
||||
},
|
||||
},*/
|
||||
currentAccountPicture: CircleAvatar(
|
||||
child: Text(
|
||||
widget.homeAssistant.userAvatarText,
|
||||
@ -368,19 +367,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
||||
),
|
||||
)
|
||||
);
|
||||
if (_accountMenuExpanded) {
|
||||
menuItems.addAll([
|
||||
ListTile(
|
||||
leading: Icon(Icons.settings),
|
||||
title: Text("Settings"),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushNamed('/connection-settings', arguments: {"homeAssistant", widget.homeAssistant});
|
||||
},
|
||||
),
|
||||
Divider(),
|
||||
]);
|
||||
} else {
|
||||
if (widget.homeAssistant != null && widget.homeAssistant.panels.isNotEmpty) {
|
||||
widget.homeAssistant.panels.forEach((Panel panel) {
|
||||
if (!panel.isHidden) {
|
||||
@ -403,6 +389,24 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
||||
]);
|
||||
}
|
||||
menuItems.addAll([
|
||||
ListTile(
|
||||
leading: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:login-variant")),
|
||||
title: Text("Connection settings"),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushNamed('/connection-settings', arguments: {"homeAssistant", widget.homeAssistant});
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:logout-variant")),
|
||||
title: Text("Logout"),
|
||||
onTap: () {
|
||||
widget.homeAssistant.logout().then((_) {
|
||||
widget.homeAssistant.disconnect().then((__) => _refreshData());
|
||||
});
|
||||
},
|
||||
),
|
||||
Divider(),
|
||||
new ListTile(
|
||||
leading: Icon(Icons.insert_drive_file),
|
||||
title: Text("Log"),
|
||||
@ -448,7 +452,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
||||
applicationVersion: appVersion
|
||||
)
|
||||
]);
|
||||
}
|
||||
return new Drawer(
|
||||
child: ListView(
|
||||
children: menuItems,
|
||||
@ -632,9 +635,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
||||
icon: Icon(Icons.menu),
|
||||
onPressed: () {
|
||||
_scaffoldKey.currentState.openDrawer();
|
||||
setState(() {
|
||||
_accountMenuExpanded = false;
|
||||
});
|
||||
},
|
||||
),
|
||||
bottom: empty ? null : TabBar(
|
||||
|
Reference in New Issue
Block a user