From f72675c35154e7a5daad4eda0323bd308b828820 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sat, 28 May 2022 10:01:03 +0200 Subject: [PATCH] feat: Better sign up UX and allow signup without password --- assets/l10n/intl_en.arb | 3 +- lib/config/themes.dart | 1 + lib/pages/sign_up/signup.dart | 54 ++++++++++++++++++++++-------- lib/pages/sign_up/signup_view.dart | 23 ++++++++++++- pubspec.lock | 2 +- 5 files changed, 66 insertions(+), 17 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index e4bcfcbd..b0741688 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2825,5 +2825,6 @@ "placeholders": { "user": {} } - } + }, + "noEmailWarning": "Please enter a valid email address. Otherwise you won't be able to reset your password. If you don't want to, tap again on the button to continue." } diff --git a/lib/config/themes.dart b/lib/config/themes.dart index d462b821..ac20d99e 100644 --- a/lib/config/themes.dart +++ b/lib/config/themes.dart @@ -34,6 +34,7 @@ abstract class FluffyThemes { prefixIconColor: Colors.black, iconColor: Colors.black, errorText: errorText, + errorMaxLines: 4, errorStyle: TextStyle( color: Colors.red.shade200, shadows: const [ diff --git a/lib/pages/sign_up/signup.dart b/lib/pages/sign_up/signup.dart index bd63faf9..c6db6815 100644 --- a/lib/pages/sign_up/signup.dart +++ b/lib/pages/sign_up/signup.dart @@ -17,10 +17,15 @@ class SignupPage extends StatefulWidget { class SignupPageController extends State { final TextEditingController passwordController = TextEditingController(); + final TextEditingController password2Controller = TextEditingController(); final TextEditingController emailController = TextEditingController(); String? error; bool loading = false; - bool showPassword = true; + bool showPassword = false; + bool noEmailWarningConfirmed = false; + bool displaySecondPasswordField = false; + + static const int minPassLength = 8; void toggleShowPassword() => setState(() => showPassword = !showPassword); @@ -28,20 +33,39 @@ class SignupPageController extends State { final GlobalKey formKey = GlobalKey(); + void onPasswordType(String text) { + if (text.length >= minPassLength && !displaySecondPasswordField) { + setState(() { + displaySecondPasswordField = true; + }); + } + } + String? password1TextFieldValidator(String? value) { - const minLength = 8; if (value!.isEmpty) { return L10n.of(context)!.chooseAStrongPassword; } - if (value.length < minLength) { - return L10n.of(context)!.pleaseChooseAtLeastChars(minLength.toString()); + if (value.length < minPassLength) { + return L10n.of(context)! + .pleaseChooseAtLeastChars(minPassLength.toString()); + } + return null; + } + + String? password2TextFieldValidator(String? value) { + if (value!.isEmpty) { + return L10n.of(context)!.repeatPassword; + } + if (value != passwordController.text) { + return L10n.of(context)!.passwordsDoNotMatch; } return null; } String? emailTextFieldValidator(String? value) { - if (value!.isEmpty) { - return L10n.of(context)!.addEmail; + if (value!.isEmpty && !noEmailWarningConfirmed) { + noEmailWarningConfirmed = true; + return L10n.of(context)!.noEmailWarning; } if (value.isNotEmpty && !value.contains('@')) { return L10n.of(context)!.pleaseEnterValidEmail; @@ -62,14 +86,16 @@ class SignupPageController extends State { try { final client = Matrix.of(context).getLoginClient(); final email = emailController.text; - Matrix.of(context).currentClientSecret = - DateTime.now().millisecondsSinceEpoch.toString(); - Matrix.of(context).currentThreepidCreds = - await client.requestTokenToRegisterEmail( - Matrix.of(context).currentClientSecret, - email, - 0, - ); + if (email.isNotEmpty) { + Matrix.of(context).currentClientSecret = + DateTime.now().millisecondsSinceEpoch.toString(); + Matrix.of(context).currentThreepidCreds = + await client.requestTokenToRegisterEmail( + Matrix.of(context).currentClientSecret, + email, + 0, + ); + } await client.uiaRequestBackground( (auth) => client.register( diff --git a/lib/pages/sign_up/signup_view.dart b/lib/pages/sign_up/signup_view.dart index 41bc4595..8f27b3c9 100644 --- a/lib/pages/sign_up/signup_view.dart +++ b/lib/pages/sign_up/signup_view.dart @@ -32,8 +32,9 @@ class SignupPageView extends StatelessWidget { child: TextFormField( readOnly: controller.loading, autocorrect: false, + onChanged: controller.onPasswordType, autofillHints: - controller.loading ? null : [AutofillHints.password], + controller.loading ? null : [AutofillHints.newPassword], controller: controller.passwordController, obscureText: !controller.showPassword, validator: controller.password1TextFieldValidator, @@ -56,6 +57,26 @@ class SignupPageView extends StatelessWidget { ), ), ), + if (controller.displaySecondPasswordField) + Padding( + padding: const EdgeInsets.all(16.0), + child: TextFormField( + readOnly: controller.loading, + autocorrect: false, + autofillHints: + controller.loading ? null : [AutofillHints.newPassword], + controller: controller.password2Controller, + obscureText: !controller.showPassword, + validator: controller.password2TextFieldValidator, + decoration: FluffyThemes.loginTextFieldDecoration( + prefixIcon: const Icon( + Icons.repeat_outlined, + color: Colors.black, + ), + hintText: L10n.of(context)!.repeatPassword, + ), + ), + ), Padding( padding: const EdgeInsets.all(16.0), child: TextFormField( diff --git a/pubspec.lock b/pubspec.lock index 44ac4e31..3f239239 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -932,7 +932,7 @@ packages: description: path: "." ref: null-safety - resolved-ref: "5aa8786475bca1b90ff35409eff3e0f5a4768601" + resolved-ref: "2906e65ffaa96afbe6c72e8477d4dfcdfd06c2c3" url: "https://github.com/TheOneWithTheBraid/keyboard_shortcuts.git" source: git version: "0.1.4"