From 165c64ce36544fa0d09a96884896aebec1cfadc4 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 21 Sep 2020 17:50:01 +0200 Subject: [PATCH] Implement missing account settings --- CHANGELOG.md | 2 + lib/components/dialogs/simple_dialogs.dart | 2 + lib/l10n/intl_messages.arb | 22 +++++++- lib/l10n/l10n.dart | 10 ++++ lib/l10n/messages_messages.dart | 8 +++ lib/views/settings.dart | 63 ++++++++++++++++++++++ 6 files changed, 106 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe1efa3..46ee3b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ - Display messages with up to 10 emotes or emoji bigger - New design for the chat list and message bubbles - Implement reactions +- Implement password change +- Implement deactivate user account ### Fixes - Timeline randomly resorting while more history is being fetched - Automatically request history if the "load more" button is on the screen diff --git a/lib/components/dialogs/simple_dialogs.dart b/lib/components/dialogs/simple_dialogs.dart index 4336ffb..4a9e7eb 100644 --- a/lib/components/dialogs/simple_dialogs.dart +++ b/lib/components/dialogs/simple_dialogs.dart @@ -79,6 +79,7 @@ class SimpleDialogs { String contentText, String confirmText, String cancelText, + bool dangerous = false, }) async { var confirmed = false; await showDialog( @@ -98,6 +99,7 @@ class SimpleDialogs { child: Text( confirmText?.toUpperCase() ?? L10n.of(context).confirm.toUpperCase(), + style: TextStyle(color: dangerous ? Colors.red : null), ), onPressed: () { confirmed = true; diff --git a/lib/l10n/intl_messages.arb b/lib/l10n/intl_messages.arb index 3c56294..d288ec8 100644 --- a/lib/l10n/intl_messages.arb +++ b/lib/l10n/intl_messages.arb @@ -1,5 +1,5 @@ { - "@@last_modified": "2020-09-19T15:27:28.862887", + "@@last_modified": "2020-09-21T17:49:17.725032", "About": "About", "@About": { "type": "text", @@ -453,6 +453,16 @@ "type": "text", "placeholders": {} }, + "This will deactivate your user account. This can not be undone! Are you sure?": "This will deactivate your user account. This can not be undone! Are you sure?", + "@This will deactivate your user account. This can not be undone! Are you sure?": { + "type": "text", + "placeholders": {} + }, + "Delete account": "Delete account", + "@Delete account": { + "type": "text", + "placeholders": {} + }, "Delete message": "Delete message", "@Delete message": { "type": "text", @@ -1006,6 +1016,11 @@ "type": "text", "placeholders": {} }, + "Password has been changed": "Password has been changed", + "@Password has been changed": { + "type": "text", + "placeholders": {} + }, "Pick image": "Pick image", "@Pick image": { "type": "text", @@ -1617,6 +1632,11 @@ "type": "text", "placeholders": {} }, + "Warning!": "Warning!", + "@Warning!": { + "type": "text", + "placeholders": {} + }, "Wallpaper": "Wallpaper", "@Wallpaper": { "type": "text", diff --git a/lib/l10n/l10n.dart b/lib/l10n/l10n.dart index eb8a3e8..944cc76 100644 --- a/lib/l10n/l10n.dart +++ b/lib/l10n/l10n.dart @@ -342,6 +342,11 @@ class L10n extends MatrixLocalizations { String get delete => Intl.message("Delete"); + String get deactivateAccountWarning => Intl.message( + 'This will deactivate your user account. This can not be undone! Are you sure?'); + + String get deleteAccount => Intl.message('Delete account'); + String get deleteMessage => Intl.message("Delete message"); String get deny => Intl.message("Deny"); @@ -636,6 +641,9 @@ class L10n extends MatrixLocalizations { String get password => Intl.message("Password"); + String get passwordHasBeenChanged => + Intl.message('Password has been changed'); + String get pickImage => Intl.message('Pick image'); String get pin => Intl.message('Pin'); @@ -988,6 +996,8 @@ class L10n extends MatrixLocalizations { Intl.message("Waiting for partner to accept the numbers...", name: "waitingPartnerNumbers"); + String get warning => Intl.message('Warning!'); + String get wallpaper => Intl.message("Wallpaper"); String get warningEncryptionInBeta => Intl.message( diff --git a/lib/l10n/messages_messages.dart b/lib/l10n/messages_messages.dart index 858ab44..136686f 100644 --- a/lib/l10n/messages_messages.dart +++ b/lib/l10n/messages_messages.dart @@ -239,6 +239,8 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage("Currently active"), "Dark": MessageLookupByLibrary.simpleMessage("Dark"), "Delete": MessageLookupByLibrary.simpleMessage("Delete"), + "Delete account": + MessageLookupByLibrary.simpleMessage("Delete account"), "Delete message": MessageLookupByLibrary.simpleMessage("Delete message"), "Deny": MessageLookupByLibrary.simpleMessage("Deny"), @@ -362,6 +364,8 @@ class MessageLookup extends MessageLookupByLibrary { "Participating user devices": MessageLookupByLibrary.simpleMessage("Participating user devices"), "Password": MessageLookupByLibrary.simpleMessage("Password"), + "Password has been changed": + MessageLookupByLibrary.simpleMessage("Password has been changed"), "Pick image": MessageLookupByLibrary.simpleMessage("Pick image"), "Pin": MessageLookupByLibrary.simpleMessage("Pin"), "Please be aware that you need Pantalaimon to use end-to-end encryption for now.": @@ -438,6 +442,9 @@ class MessageLookup extends MessageLookupByLibrary { "They Match": MessageLookupByLibrary.simpleMessage("They Match"), "This room has been archived.": MessageLookupByLibrary.simpleMessage( "This room has been archived."), + "This will deactivate your user account. This can not be undone! Are you sure?": + MessageLookupByLibrary.simpleMessage( + "This will deactivate your user account. This can not be undone! Are you sure?"), "Thursday": MessageLookupByLibrary.simpleMessage("Thursday"), "Try to send again": MessageLookupByLibrary.simpleMessage("Try to send again"), @@ -464,6 +471,7 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage("Visible for everyone"), "Voice message": MessageLookupByLibrary.simpleMessage("Voice message"), "Wallpaper": MessageLookupByLibrary.simpleMessage("Wallpaper"), + "Warning!": MessageLookupByLibrary.simpleMessage("Warning!"), "Wednesday": MessageLookupByLibrary.simpleMessage("Wednesday"), "Welcome to the cutest instant messenger in the matrix network.": MessageLookupByLibrary.simpleMessage( diff --git a/lib/views/settings.dart b/lib/views/settings.dart index 7d00361..d9beaba 100644 --- a/lib/views/settings.dart +++ b/lib/views/settings.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:bot_toast/bot_toast.dart'; import 'package:famedlysdk/famedlysdk.dart'; import 'package:fluffychat/components/settings_themes.dart'; import 'package:fluffychat/config/app_config.dart'; @@ -55,6 +56,52 @@ class _SettingsState extends State { .tryRequestWithLoadingDialog(matrix.client.logout()); } + void _changePasswordAccountAction(BuildContext context) async { + final oldPassword = await SimpleDialogs(context).enterText( + password: true, + titleText: L10n.of(context).pleaseEnterYourPassword, + ); + if (oldPassword == null) return; + final newPassword = await SimpleDialogs(context).enterText( + password: true, + titleText: L10n.of(context).chooseAStrongPassword, + ); + if (newPassword == null) return; + await SimpleDialogs(context).tryRequestWithLoadingDialog( + Matrix.of(context) + .client + .changePassword(newPassword, oldPassword: oldPassword), + ); + BotToast.showText(text: L10n.of(context).passwordHasBeenChanged); + } + + void _deleteAccountAction(BuildContext context) async { + if (await SimpleDialogs(context).askConfirmation( + titleText: L10n.of(context).warning, + contentText: L10n.of(context).deactivateAccountWarning, + dangerous: true, + ) == + false) { + return; + } + if (await SimpleDialogs(context).askConfirmation(dangerous: true) == + false) { + return; + } + final password = await SimpleDialogs(context).enterText( + password: true, + titleText: L10n.of(context).pleaseEnterYourPassword, + ); + if (password == null) return; + await SimpleDialogs(context).tryRequestWithLoadingDialog( + Matrix.of(context).client.deactivateAccount(auth: { + 'type': 'm.login.password', + 'user': Matrix.of(context).client.userID, + 'password': password, + }), + ); + } + void setJitsiInstanceAction(BuildContext context) async { var jitsi = await SimpleDialogs(context).enterText( titleText: L10n.of(context).editJitsiInstance, @@ -359,11 +406,27 @@ class _SettingsState extends State { title: Text(L10n.of(context).sendBugReports), onTap: () => SentryController.toggleSentryAction(context), ), + Divider(thickness: 1), + ListTile( + trailing: Icon(Icons.vpn_key), + title: Text( + 'Change password', + ), + onTap: () => _changePasswordAccountAction(context), + ), ListTile( trailing: Icon(Icons.exit_to_app), title: Text(L10n.of(context).logout), onTap: () => logoutAction(context), ), + ListTile( + trailing: Icon(Icons.delete_forever), + title: Text( + L10n.of(context).deleteAccount, + style: TextStyle(color: Colors.red), + ), + onTap: () => _deleteAccountAction(context), + ), Divider(thickness: 1), ListTile( title: Text(