1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Can disconnect current user from all his devices

This commit is contained in:
Pierre HUBERT 2020-05-01 09:42:01 +02:00
parent 02e60ad87c
commit 9b427b9683
2 changed files with 32 additions and 0 deletions

View File

@ -139,4 +139,12 @@ class AccountHelper {
if (_currentUserID == -1) throw "Current user ID has not been loaded yet!"; if (_currentUserID == -1) throw "Current user ID has not been loaded yet!";
return _currentUserID; return _currentUserID;
} }
/// Disconnect all the devices of the current user
///
/// Throws in case of failure
static Future<void> disconnectAllDevices() async {
await APIRequest(uri: "account/disconnect_all_devices", needLogin: true)
.execWithThrow();
}
} }

View File

@ -1,3 +1,4 @@
import 'package:comunic/helpers/account_helper.dart';
import 'package:comunic/helpers/settings_helper.dart'; import 'package:comunic/helpers/settings_helper.dart';
import 'package:comunic/models/security_settings.dart'; import 'package:comunic/models/security_settings.dart';
import 'package:comunic/ui/dialogs/input_new_password_dialog.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..."), "Your security questions can be used to recover an access to your account when you loose your password..."),
onTap: _changeSecurityQuestions, 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!")); 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 { class _SecurityQuestionsDialog extends StatefulWidget {