From a5896e7c158b1b44a679402f0af40ae685401a86 Mon Sep 17 00:00:00 2001 From: "Lin, Hung-Shin" Date: Thu, 2 Nov 2023 11:36:53 +0800 Subject: [PATCH] feat: remove username length limit --- app/src/views/ChooseUsernamePage.vue | 10 +++++----- app/src/views/RegisterPage.vue | 3 --- packages/utils/auth.js | 10 +++++----- server/src/api/validators/authValidator.js | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/src/views/ChooseUsernamePage.vue b/app/src/views/ChooseUsernamePage.vue index f165c78..082aae9 100644 --- a/app/src/views/ChooseUsernamePage.vue +++ b/app/src/views/ChooseUsernamePage.vue @@ -6,11 +6,11 @@ import { TooManyRequestsError, ValidationError } from '../utils/errors' import { checkUsername, chooseUsername } from '../utils/auth' async function check({ username, error }) { - if (username && !isValidUsername(username)) { - error('Invalid username.') - return - } - if (username.length > 3) { + if (username) { + if (!isValidUsername(username)) { + error('Invalid username.') + return + } try { await checkUsername(username) } catch (err) { diff --git a/app/src/views/RegisterPage.vue b/app/src/views/RegisterPage.vue index 39918d8..5e691a7 100644 --- a/app/src/views/RegisterPage.vue +++ b/app/src/views/RegisterPage.vue @@ -48,9 +48,6 @@ async function check({ username, email, password, error }) { ) return } - if (!(username && email && password)) { - return - } try { await checkUsername(username) } catch (err) { diff --git a/packages/utils/auth.js b/packages/utils/auth.js index cd26d47..59caef6 100644 --- a/packages/utils/auth.js +++ b/packages/utils/auth.js @@ -1,15 +1,15 @@ export function isValidUsername(username) { + // check if the username is between 1 and 32 characters + if (username.length > 32) { + return false + } + // Define a regular expression pattern for a valid Linux username. const usernamePattern = /^[a-z][a-z0-9_-]*$/ // Test the username against the pattern. if (!usernamePattern.test(username)) return false - // check if the username is between 1 and 32 characters - if (username.length < 4 || username.length > 32) { - return false - } - const reservedWords = [ 'root', 'admin', diff --git a/server/src/api/validators/authValidator.js b/server/src/api/validators/authValidator.js index 69ded44..9deda55 100644 --- a/server/src/api/validators/authValidator.js +++ b/server/src/api/validators/authValidator.js @@ -61,4 +61,4 @@ export const registerFromSessionValidators = [checkNewUsername(), noError] export const loginValidators = [checkLogin(), noError] -export const checkUsernameValidators = [checkUsername(), noError] +export const checkUsernameValidators = [checkNewUsername(), noError]