mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
feat: remove username length limit
This commit is contained in:
1 parent
b09aa0debf
commit
a5896e7c15
4 files changed
+8
-11
No files matched your search
@@ -6,11 +6,11 @@ import { TooManyRequestsError, ValidationError } from '../utils/errors'
|
|||||||
import { checkUsername, chooseUsername } from '../utils/auth'
|
import { checkUsername, chooseUsername } from '../utils/auth'
|
||||||
|
|
||||||
async function check({ username, error }) {
|
async function check({ username, error }) {
|
||||||
if (username && !isValidUsername(username)) {
|
if (username) {
|
||||||
|
if (!isValidUsername(username)) {
|
||||||
error('Invalid username.')
|
error('Invalid username.')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (username.length > 3) {
|
|
||||||
try {
|
try {
|
||||||
await checkUsername(username)
|
await checkUsername(username)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -48,9 +48,6 @@ async function check({ username, email, password, error }) {
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!(username && email && password)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
await checkUsername(username)
|
await checkUsername(username)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
export function isValidUsername(username) {
|
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.
|
// Define a regular expression pattern for a valid Linux username.
|
||||||
const usernamePattern = /^[a-z][a-z0-9_-]*$/
|
const usernamePattern = /^[a-z][a-z0-9_-]*$/
|
||||||
|
|
||||||
// Test the username against the pattern.
|
// Test the username against the pattern.
|
||||||
if (!usernamePattern.test(username)) return false
|
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 = [
|
const reservedWords = [
|
||||||
'root',
|
'root',
|
||||||
'admin',
|
'admin',
|
||||||
|
|||||||
@@ -61,4 +61,4 @@ export const registerFromSessionValidators = [checkNewUsername(), noError]
|
|||||||
|
|
||||||
export const loginValidators = [checkLogin(), noError]
|
export const loginValidators = [checkLogin(), noError]
|
||||||
|
|
||||||
export const checkUsernameValidators = [checkUsername(), noError]
|
export const checkUsernameValidators = [checkNewUsername(), noError]
|
||||||
Reference in new issue
Block a user