Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Sign up page: Fix trimmed text not being done correctly #1545

Merged
merged 2 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/smooth_app/lib/helpers/user_management_helper.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:flutter/widgets.dart';

class UserManagementHelper {
UserManagementHelper._();

Expand All @@ -20,3 +22,7 @@ class UserManagementHelper {

static bool isPasswordValid(final String password) => password.length >= 6;
}

extension UserManagementTextController on TextEditingController {
String get trimmedText => text.trim();
}
34 changes: 17 additions & 17 deletions packages/smooth_app/lib/pages/user_management/sign_up_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@ class _SignUpPageState extends State<SignUpPage> {
validator: (String? value) {
if (value == null || value.isEmpty) {
return appLocalizations.sign_up_page_email_error_empty;
}
_emailController.text = value.trim();
if (!UserManagementHelper.isEmailValid(value.trim())) {
} else if (!UserManagementHelper.isEmailValid(
_emailController.trimmedText)) {
return appLocalizations.sign_up_page_email_error_invalid;
} else {
return null;
}

return null;
},
),
const SizedBox(height: space),
Expand All @@ -108,8 +107,8 @@ class _SignUpPageState extends State<SignUpPage> {
if (value == null || value.isEmpty) {
return appLocalizations.sign_up_page_username_error_empty;
}
_userController.text = value.trim();
if (!UserManagementHelper.isUsernameValid(value.trim())) {
if (!UserManagementHelper.isUsernameValid(
_userController.trimmedText)) {
return appLocalizations.sign_up_page_username_description;
}
return null;
Expand All @@ -128,11 +127,11 @@ class _SignUpPageState extends State<SignUpPage> {
validator: (String? value) {
if (value == null || value.isEmpty) {
return appLocalizations.sign_up_page_password_error_empty;
}
if (!UserManagementHelper.isPasswordValid(value)) {
} else if (!UserManagementHelper.isPasswordValid(value)) {
return appLocalizations.sign_up_page_password_error_invalid;
} else {
return null;
}
return null;
},
),
const SizedBox(height: space),
Expand All @@ -149,12 +148,13 @@ class _SignUpPageState extends State<SignUpPage> {
if (value == null || value.isEmpty) {
return appLocalizations
.sign_up_page_confirm_password_error_empty;
}
if (value != _password1Controller.text) {
} else if (_password2Controller.text !=
_password1Controller.text) {
Comment on lines +151 to +152
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't both of them be trimedText too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering… but the user may want some spaces in its password
… or maybe we should enforce rules on passwords

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd definitively sense to not allow spaces in passwords

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to let the code as it, and to open in parallel an issue and discuss about this case (which is not the primary goal of this PR)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue with the password policy: #1555

return appLocalizations
.sign_up_page_confirm_password_error_invalid;
} else {
return null;
}
return null;
},
),
const SizedBox(height: space),
Expand Down Expand Up @@ -282,17 +282,17 @@ class _SignUpPageState extends State<SignUpPage> {
return;
}
final User user = User(
userId: _userController.text,
userId: _userController.trimmedText,
password: _password1Controller.text,
);
final Status? status = await LoadingDialog.run<Status>(
context: context,
future: OpenFoodAPIClient.register(
user: user,
name: _displayNameController.text,
email: _emailController.text,
name: _displayNameController.trimmedText,
email: _emailController.trimmedText,
newsletter: _subscribe,
orgName: _foodProducer ? _brandController.text : null,
orgName: _foodProducer ? _brandController.trimmedText : null,
),
title: AppLocalizations.of(context)!.sign_up_page_action_doing_it,
);
Expand Down