X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fusers.ts;h=9df550fc21227bae8845f665d1039f3164335dd7;hb=2a4c0d8bbe29178ae90e776bb9453f86e6d23bd9;hp=b04970108ef5171174af2509d2ba36b63f2959c0;hpb=3318147300b4f998adf728eb0a5a14a4c1829c51;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index b04970108..9df550fc2 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts @@ -1,4 +1,3 @@ -import { values } from 'lodash' import validator from 'validator' import { UserRole } from '@shared/models' import { isEmailEnabled } from '../../initializers/config' @@ -27,9 +26,9 @@ function isUserVideoQuotaDailyValid (value: string) { } function isUserUsernameValid (value: string) { - const max = USERS_CONSTRAINTS_FIELDS.USERNAME.max - const min = USERS_CONSTRAINTS_FIELDS.USERNAME.min - return exists(value) && validator.matches(value, new RegExp(`^[a-z0-9._]{${min},${max}}$`)) + return exists(value) && + validator.matches(value, new RegExp(`^[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?$`)) && + validator.isLength(value, USERS_CONSTRAINTS_FIELDS.USERNAME) } function isUserDisplayNameValid (value: string) { @@ -44,9 +43,9 @@ function isUserEmailVerifiedValid (value: any) { return isBooleanValid(value) } -const nsfwPolicies = values(NSFW_POLICY_TYPES) +const nsfwPolicies = new Set(Object.values(NSFW_POLICY_TYPES)) function isUserNSFWPolicyValid (value: any) { - return exists(value) && nsfwPolicies.includes(value) + return exists(value) && nsfwPolicies.has(value) } function isUserP2PEnabledValid (value: any) {