X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fusers.ts;h=d6e91ad35df62351fe66720caf8c3b7b977ba030;hb=e62f03ae0412f4efa62917d8741bc1a39e8ed7fc;hp=b4d5751e70281d0ba6f7941fbb6bbda564bb5744;hpb=7cde3b9c2e84ea20bb0aae4544598483cde9e22c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index b4d5751e7..d6e91ad35 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts @@ -3,6 +3,7 @@ import { UserRole } from '../../../shared' import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' import { exists, isArray, isBooleanValid, isFileValid } from './misc' import { values } from 'lodash' +import { isEmailEnabled } from '../../initializers/config' const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS @@ -10,6 +11,13 @@ function isUserPasswordValid (value: string) { return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.PASSWORD) } +function isUserPasswordValidOrEmpty (value: string) { + // Empty password is only possible if emailing is enabled. + if (value === '') return isEmailEnabled() + + return isUserPasswordValid(value) +} + function isUserVideoQuotaValid (value: string) { return exists(value) && validator.isInt(value + '', USERS_CONSTRAINTS_FIELDS.VIDEO_QUOTA) } @@ -38,7 +46,7 @@ function isUserEmailVerifiedValid (value: any) { const nsfwPolicies = values(NSFW_POLICY_TYPES) function isUserNSFWPolicyValid (value: any) { - return exists(value) && nsfwPolicies.indexOf(value) !== -1 + return exists(value) && nsfwPolicies.includes(value) } function isUserWebTorrentEnabledValid (value: any) { @@ -103,6 +111,7 @@ export { isUserVideosHistoryEnabledValid, isUserBlockedValid, isUserPasswordValid, + isUserPasswordValidOrEmpty, isUserVideoLanguages, isUserBlockedReasonValid, isUserRoleValid,