From c4f3b7641448b2f6d6cc78a0806046534da2aa72 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Sat, 8 Oct 2022 16:14:20 +0000 Subject: [PATCH 1/3] fix(validations): Make validations and errors text more specific --- assets/translations/en.json | 17 +++++++++-------- assets/translations/ru.json | 17 +++++++++-------- .../forms/factories/field_cubit_factory.dart | 4 ++-- .../initializing/dns_provider_form_cubit.dart | 2 +- .../setup/initializing/provider_form_cubit.dart | 2 +- lib/logic/cubit/forms/user/ssh_form_cubit.dart | 4 ++-- lib/ui/pages/users/new_user.dart | 8 ++++++++ 7 files changed, 32 insertions(+), 22 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index 069e0c74..b77371aa 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -258,6 +258,7 @@ "could_not_create_user": "Couldn't create user", "could_not_delete_user": "Couldn't delete user", "could_not_add_ssh_key": "Couldn't add SSH key", + "username_rule": "Must contain only lowercase latin letters, digits and underscores, should not start with a digit", "email_login": "Email login", "no_ssh_notice": "Only email and SSH accounts are created for this user. Single Sign On for all services is coming soon." }, @@ -418,13 +419,13 @@ "reset_user_password": "Reset password of user" }, "validations": { - "required": "Required.", - "invalid_format": "Invalid format.", - "root_name": "User name cannot be 'root'.", - "key_format": "Invalid key format.", - "length_not_equal": "Length is []. Should be {}.", - "length_longer": "Length is []. Should be shorter than or equal to {}.", - "user_already_exist": "This user already exists.", - "key_already_exists": "This key already exists." + "required": "Required", + "already_exist": "Already exists", + "invalid_format": "Invalid format", + "invalid_format_password": "Must not contain empty characters", + "invalid_format_ssh": "Must follow the SSH key format", + "root_name": "Cannot be 'root'", + "length_not_equal": "Length is [], should be {}", + "length_longer": "Length is [], should be shorter than or equal to {}" } } diff --git a/assets/translations/ru.json b/assets/translations/ru.json index d29ae6dc..11194ea0 100644 --- a/assets/translations/ru.json +++ b/assets/translations/ru.json @@ -258,6 +258,7 @@ "could_not_create_user": "Не удалось создать пользователя", "could_not_delete_user": "Не удалось стереть пользователя", "could_not_add_ssh_key": "Не удалось создать SSH ключить", + "username_rule": "Может содержать только маленькие латинские буквы, цифры, подчёркивания, не может начинаться с цифр", "email_login": "Авторизация по Email", "no_ssh_notice": "Для этого пользователя созданы только SSH и Email аккаунты. Единая авторизация для всех сервисов ещё не реализована." }, @@ -419,13 +420,13 @@ "reset_user_password": "Сбросить пароль пользователя" }, "validations": { - "required": "Обязательное поле.", - "invalid_format": "Неверный формат.", - "root_name": "Имя пользователя не может быть 'root'.", - "key_format": "Неверный формат.", - "length_not_equal": "Длина строки []. Должно быть равно {}.", - "length_longer": "Длина строки []. Должно быть меньше либо равно {}.", - "user_already_exist": "Имя уже используется.", - "key_already_exists": "Этот ключ уже добавлен." + "required": "Обязательное поле", + "already_exist": "Уже существует", + "invalid_format": "Неверный формат", + "invalid_format_password": "Должен не содержать пустые символы", + "invalid_format_ssh": "Должен следовать формату SSH ключей", + "root_name": "Имя пользователя не может быть 'root'", + "length_not_equal": "Длина строки [], должно быть равно {}", + "length_longer": "Длина строки [], должно быть меньше либо равно {}" } } diff --git a/lib/logic/cubit/forms/factories/field_cubit_factory.dart b/lib/logic/cubit/forms/factories/field_cubit_factory.dart index 62067cea..724dfb4c 100644 --- a/lib/logic/cubit/forms/factories/field_cubit_factory.dart +++ b/lib/logic/cubit/forms/factories/field_cubit_factory.dart @@ -28,7 +28,7 @@ class FieldCubitFactory { ValidationModel( (final String login) => context.read().state.isLoginRegistered(login), - 'validations.user_already_exist'.tr(), + 'validations.already_exist'.tr(), ), RequiredStringValidation('validations.required'.tr()), LengthStringLongerValidation(userMaxLength), @@ -52,7 +52,7 @@ class FieldCubitFactory { RequiredStringValidation('validations.required'.tr()), ValidationModel( passwordForbiddenRegExp.hasMatch, - 'validations.invalid_format'.tr(), + 'validations.invalid_format_password'.tr(), ), ], ); diff --git a/lib/logic/cubit/forms/setup/initializing/dns_provider_form_cubit.dart b/lib/logic/cubit/forms/setup/initializing/dns_provider_form_cubit.dart index d27d7053..c2348a69 100644 --- a/lib/logic/cubit/forms/setup/initializing/dns_provider_form_cubit.dart +++ b/lib/logic/cubit/forms/setup/initializing/dns_provider_form_cubit.dart @@ -14,7 +14,7 @@ class DnsProviderFormCubit extends FormCubit { RequiredStringValidation('validations.required'.tr()), ValidationModel( regExp.hasMatch, - 'validations.key_format'.tr(), + 'validations.invalid_format'.tr(), ), LengthStringNotEqualValidation(40) ], diff --git a/lib/logic/cubit/forms/setup/initializing/provider_form_cubit.dart b/lib/logic/cubit/forms/setup/initializing/provider_form_cubit.dart index 9f3b5d58..44f40b57 100644 --- a/lib/logic/cubit/forms/setup/initializing/provider_form_cubit.dart +++ b/lib/logic/cubit/forms/setup/initializing/provider_form_cubit.dart @@ -15,7 +15,7 @@ class ProviderFormCubit extends FormCubit { RequiredStringValidation('validations.required'.tr()), ValidationModel( regExp.hasMatch, - 'validations.key_format'.tr(), + 'validations.invalid_format'.tr(), ), LengthStringNotEqualValidation(64) ], diff --git a/lib/logic/cubit/forms/user/ssh_form_cubit.dart b/lib/logic/cubit/forms/user/ssh_form_cubit.dart index ba992af0..9ed389d2 100644 --- a/lib/logic/cubit/forms/user/ssh_form_cubit.dart +++ b/lib/logic/cubit/forms/user/ssh_form_cubit.dart @@ -21,7 +21,7 @@ class SshFormCubit extends FormCubit { ValidationModel( (final String newKey) => user.sshKeys.any((final String key) => key == newKey), - 'validations.key_already_exists'.tr(), + 'validations.already_exists'.tr(), ), RequiredStringValidation('validations.required'.tr()), ValidationModel( @@ -30,7 +30,7 @@ class SshFormCubit extends FormCubit { print(keyRegExp.hasMatch(s)); return !keyRegExp.hasMatch(s); }, - 'validations.invalid_format'.tr(), + 'validations.invalid_format_ssh'.tr(), ), ], ); diff --git a/lib/ui/pages/users/new_user.dart b/lib/ui/pages/users/new_user.dart index 38ec74b7..c0f3496c 100644 --- a/lib/ui/pages/users/new_user.dart +++ b/lib/ui/pages/users/new_user.dart @@ -55,6 +55,14 @@ class NewUser extends StatelessWidget { child: Column( mainAxisSize: MainAxisSize.min, children: [ + if (context.read().state.isErrorShown) + Text( + 'users.username_rule'.tr(), + style: TextStyle( + color: Theme.of(context).colorScheme.error, + ), + ), + const SizedBox(width: 14), IntrinsicHeight( child: CubitFormTextField( formFieldCubit: context.read().login, From f4e588c435c2989084f7550a55255d31a46b8662 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Sat, 8 Oct 2022 19:22:08 +0000 Subject: [PATCH 2/3] fix(user): Replace cubit context read with state variable on login page --- lib/ui/pages/setup/initializing.dart | 8 ++++++++ lib/ui/pages/users/new_user.dart | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ui/pages/setup/initializing.dart b/lib/ui/pages/setup/initializing.dart index 102c5a9b..00640df6 100644 --- a/lib/ui/pages/setup/initializing.dart +++ b/lib/ui/pages/setup/initializing.dart @@ -418,6 +418,14 @@ class InitializingPage extends StatelessWidget { 'initializing.enter_nickname_and_password'.tr(), ), const Spacer(), + if (formCubitState.isErrorShown) + Text( + 'users.username_rule'.tr(), + style: TextStyle( + color: Theme.of(context).colorScheme.error, + ), + ), + const SizedBox(height: 10), CubitFormTextField( formFieldCubit: context.read().userName, textAlign: TextAlign.center, diff --git a/lib/ui/pages/users/new_user.dart b/lib/ui/pages/users/new_user.dart index c0f3496c..69215dda 100644 --- a/lib/ui/pages/users/new_user.dart +++ b/lib/ui/pages/users/new_user.dart @@ -55,7 +55,7 @@ class NewUser extends StatelessWidget { child: Column( mainAxisSize: MainAxisSize.min, children: [ - if (context.read().state.isErrorShown) + if (formCubitState.isErrorShown) Text( 'users.username_rule'.tr(), style: TextStyle( From a305e0b53f70d7ab371395531c307097197d0a77 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Sat, 8 Oct 2022 19:28:07 +0000 Subject: [PATCH 3/3] fix(assets): Change naming to conventional and consistent 'username' --- assets/translations/en.json | 6 +++--- assets/translations/ru.json | 6 +++--- lib/ui/pages/setup/initializing.dart | 18 +++++++++--------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index b77371aa..a0ce11e6 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -20,7 +20,7 @@ "connect": "Connect", "domain": "Domain", "saving": "Saving…", - "nickname": "Nickname", + "username": "Username", "loading": "Loading…", "later": "Skip to setup later", "connect_to_existing": "Connect to an existing server", @@ -258,7 +258,7 @@ "could_not_create_user": "Couldn't create user", "could_not_delete_user": "Couldn't delete user", "could_not_add_ssh_key": "Couldn't add SSH key", - "username_rule": "Must contain only lowercase latin letters, digits and underscores, should not start with a digit", + "username_rule": "Username must contain only lowercase latin letters, digits and underscores, should not start with a digit", "email_login": "Email login", "no_ssh_notice": "Only email and SSH accounts are created for this user. Single Sign On for all services is coming soon." }, @@ -287,7 +287,7 @@ "check": "Check", "one_more_restart": "One more restart to apply your security certificates.", "create_master_account": "Create master account", - "enter_nickname_and_password": "Enter a nickname and strong password", + "enter_username_and_password": "Enter username and strong password", "finish": "Everything is initialized", "checks": "Checks have been completed \n{} out of {}" }, diff --git a/assets/translations/ru.json b/assets/translations/ru.json index 11194ea0..04b832da 100644 --- a/assets/translations/ru.json +++ b/assets/translations/ru.json @@ -20,7 +20,7 @@ "connect": "Подключить", "domain": "Домен", "saving": "Сохранение…", - "nickname": "Никнейм", + "username": "Имя пользователя", "loading": "Загрузка…", "later": "Пропустить и настроить потом", "connect_to_existing": "Подключиться к существующему серверу", @@ -258,7 +258,7 @@ "could_not_create_user": "Не удалось создать пользователя", "could_not_delete_user": "Не удалось стереть пользователя", "could_not_add_ssh_key": "Не удалось создать SSH ключить", - "username_rule": "Может содержать только маленькие латинские буквы, цифры, подчёркивания, не может начинаться с цифр", + "username_rule": "Имя может содержать только маленькие латинские буквы, цифры, подчёркивания, не может начинаться с цифр", "email_login": "Авторизация по Email", "no_ssh_notice": "Для этого пользователя созданы только SSH и Email аккаунты. Единая авторизация для всех сервисов ещё не реализована." }, @@ -287,7 +287,7 @@ "check": "Проверка", "one_more_restart": "Сейчас будет дополнительная перезагрузка для активации сертификатов безопасности.", "create_master_account": "Создайте главную учетную запись", - "enter_nickname_and_password": "Введите никнейм и сложный пароль", + "enter_username_and_password": "Введите имя пользователя и сложный пароль", "finish": "Всё инициализировано", "checks": "Проверок выполнено: \n{} / {}" }, diff --git a/lib/ui/pages/setup/initializing.dart b/lib/ui/pages/setup/initializing.dart index 00640df6..02af3a59 100644 --- a/lib/ui/pages/setup/initializing.dart +++ b/lib/ui/pages/setup/initializing.dart @@ -415,23 +415,23 @@ class InitializingPage extends StatelessWidget { BrandText.h2('initializing.create_master_account'.tr()), const SizedBox(height: 10), BrandText.body2( - 'initializing.enter_nickname_and_password'.tr(), + 'initializing.enter_username_and_password'.tr(), ), const Spacer(), if (formCubitState.isErrorShown) - Text( - 'users.username_rule'.tr(), - style: TextStyle( - color: Theme.of(context).colorScheme.error, - ), - ), - const SizedBox(height: 10), + Text( + 'users.username_rule'.tr(), + style: TextStyle( + color: Theme.of(context).colorScheme.error, + ), + ), + const SizedBox(height: 10), CubitFormTextField( formFieldCubit: context.read().userName, textAlign: TextAlign.center, scrollPadding: const EdgeInsets.only(bottom: 70), decoration: InputDecoration( - hintText: 'basis.nickname'.tr(), + hintText: 'basis.username'.tr(), ), ), const SizedBox(height: 10),