From 7263787197192ccacbfa38f0d083458bc5fee787 Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Sat, 19 Feb 2022 13:11:59 +0100 Subject: [PATCH] fix: Reset password --- lib/pages/login/login.dart | 37 +++++++++++++++++++++------------ lib/pages/login/login_view.dart | 20 ++++++++++-------- pubspec.lock | 2 +- pubspec.yaml | 2 +- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/lib/pages/login/login.dart b/lib/pages/login/login.dart index 7d00e6d0..bef7697e 100644 --- a/lib/pages/login/login.dart +++ b/lib/pages/login/login.dart @@ -153,19 +153,22 @@ class LoginController extends State { final input = await showTextInputDialog( useRootNavigator: false, context: context, - title: L10n.of(context)!.enterAnEmailAddress, + title: L10n.of(context)!.passwordForgotten, + message: L10n.of(context)!.enterAnEmailAddress, okLabel: L10n.of(context)!.ok, cancelLabel: L10n.of(context)!.cancel, + fullyCapitalizedForMaterial: false, textFields: [ DialogTextField( + initialText: + usernameController.text.isEmail ? usernameController.text : '', hintText: L10n.of(context)!.enterAnEmailAddress, keyboardType: TextInputType.emailAddress, ), ], ); if (input == null) return; - final clientSecret = - Matrix.of(context).client.generateUniqueTransactionId(); + final clientSecret = DateTime.now().millisecondsSinceEpoch.toString(); final response = await showFutureLoadingDialog( context: context, future: () => @@ -182,14 +185,17 @@ class LoginController extends State { title: L10n.of(context)!.weSentYouAnEmail, message: L10n.of(context)!.pleaseClickOnLink, okLabel: L10n.of(context)!.iHaveClickedOnLink, + fullyCapitalizedForMaterial: false, ); if (ok != OkCancelResult.ok) return; final password = await showTextInputDialog( useRootNavigator: false, context: context, - title: L10n.of(context)!.chooseAStrongPassword, + title: L10n.of(context)!.passwordForgotten, + message: L10n.of(context)!.chooseAStrongPassword, okLabel: L10n.of(context)!.ok, cancelLabel: L10n.of(context)!.cancel, + fullyCapitalizedForMaterial: false, textFields: [ const DialogTextField( hintText: '******', @@ -200,17 +206,22 @@ class LoginController extends State { ], ); if (password == null) return; + final data = { + 'new_password': password.single, + "auth": AuthenticationThreePidCreds( + type: AuthenticationTypes.emailIdentity, + threepidCreds: ThreepidCreds( + sid: response.result!.sid, + clientSecret: clientSecret, + ), + ).toJson(), + }; final success = await showFutureLoadingDialog( context: context, - future: () => Matrix.of(context).getLoginClient().changePassword( - password.single, - auth: AuthenticationThreePidCreds( - type: AuthenticationTypes.emailIdentity, - threepidCreds: ThreepidCreds( - sid: response.result!.sid, - clientSecret: clientSecret, - ), - ), + future: () => Matrix.of(context).getLoginClient().request( + RequestType.POST, + '/client/r0/account/password', + data: data, ), ); if (success.error == null) { diff --git a/lib/pages/login/login_view.dart b/lib/pages/login/login_view.dart index eb6be3c7..54b21dee 100644 --- a/lib/pages/login/login_view.dart +++ b/lib/pages/login/login_view.dart @@ -88,16 +88,18 @@ class LoginView extends StatelessWidget { ), ), ), - Center( - child: TextButton( - onPressed: controller.passwordForgotten, - child: Text( - L10n.of(context)!.passwordForgotten, - style: const TextStyle( - color: Colors.blue, - decoration: TextDecoration.underline, - ), + const Divider(height: 32), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 12), + child: ElevatedButton( + onPressed: controller.loading + ? null + : controller.passwordForgotten, + style: ElevatedButton.styleFrom( + primary: Theme.of(context).secondaryHeaderColor, + onPrimary: Colors.red, ), + child: Text(L10n.of(context)!.passwordForgotten), ), ), ], diff --git a/pubspec.lock b/pubspec.lock index 1306524e..d826f033 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -960,7 +960,7 @@ packages: name: matrix url: "https://pub.dartlang.org" source: hosted - version: "0.8.10" + version: "0.8.11" matrix_api_lite: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 73f374bc..19be2a89 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,7 +57,7 @@ dependencies: intl: any localstorage: ^4.0.0+1 lottie: ^1.2.2 - matrix: ^0.8.10 + matrix: ^0.8.11 matrix_link_text: ^1.0.2 open_noti_settings: ^0.4.0 package_info_plus: ^1.3.0