diff --git a/lib/helpers/account_helper.dart b/lib/helpers/account_helper.dart index 400399a..939fb6c 100644 --- a/lib/helpers/account_helper.dart +++ b/lib/helpers/account_helper.dart @@ -139,4 +139,12 @@ class AccountHelper { if (_currentUserID == -1) throw "Current user ID has not been loaded yet!"; return _currentUserID; } + + /// Disconnect all the devices of the current user + /// + /// Throws in case of failure + static Future disconnectAllDevices() async { + await APIRequest(uri: "account/disconnect_all_devices", needLogin: true) + .execWithThrow(); + } } diff --git a/lib/ui/routes/account_settings/account_security_settings.dart b/lib/ui/routes/account_settings/account_security_settings.dart index 946003a..ed6858b 100644 --- a/lib/ui/routes/account_settings/account_security_settings.dart +++ b/lib/ui/routes/account_settings/account_security_settings.dart @@ -1,3 +1,4 @@ +import 'package:comunic/helpers/account_helper.dart'; import 'package:comunic/helpers/settings_helper.dart'; import 'package:comunic/models/security_settings.dart'; import 'package:comunic/ui/dialogs/input_new_password_dialog.dart'; @@ -49,6 +50,12 @@ class __AccountSecuritySettingsScreenBodyState "Your security questions can be used to recover an access to your account when you loose your password..."), onTap: _changeSecurityQuestions, ), + SettingsTile( + title: tr("Disconnect all your devices"), + subtitle: tr( + "Disconnect all your devices from Comunic, including the current one. Use this option if one of the device you use for Comunic was stolen."), + onTap: _disconnectAllDevices, + ), ], ) ], @@ -100,6 +107,23 @@ class __AccountSecuritySettingsScreenBodyState showSimpleSnack(context, tr("Could not update security questions!")); } } + + /// Disconnect all devices + void _disconnectAllDevices() async { + try { + if (!await showConfirmDialog( + context: context, + message: tr( + "Do you really want to disconnect all your devices from Comunic ?"))) + return; + + await AccountHelper.disconnectAllDevices(); + } catch (e, stack) { + print("Could not disconnect user on all devices! $e\n$stack"); + showSimpleSnack( + context, tr("Could not disconnect you from all your devices!")); + } + } } class _SecurityQuestionsDialog extends StatefulWidget {