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: #1585 Limited username to 20 characters #1605

Merged
merged 3 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/helpers/user_management_helper.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/widgets.dart';
import 'package:openfoodfacts/openfoodfacts.dart';

class UserManagementHelper {
UserManagementHelper._();
Expand All @@ -20,6 +21,9 @@ class UserManagementHelper {
static bool isUsernameValid(final String username) =>
username.isNotEmpty && _userRegex.hasMatch(username);

static bool isUsernameLengthValid(final String username) =>
username.length <= OpenFoodAPIClient.USER_NAME_MAX_LENGTH;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ class _SignUpPageState extends State<SignUpPage> {
_userController.trimmedText)) {
return appLocalizations.sign_up_page_username_description;
}
if (!UserManagementHelper.isUsernameLengthValid(
_userController.trimmedText)) {
const int maxLength = OpenFoodAPIClient.USER_NAME_MAX_LENGTH;
return 'Username must be less than $maxLength characters'; // TODO(vik4114): localization and translation
vik4114 marked this conversation as resolved.
Show resolved Hide resolved
}
return null;
},
),
Expand Down