mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Can disconnect current user from all his devices
This commit is contained in:
		@@ -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();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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 {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user