diff options
author | John Livingston <38844060+JohnXLivingston@users.noreply.github.com> | 2020-02-17 10:16:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-17 10:16:52 +0100 |
commit | 45f1bd72a08998c60a9dd68ff069cea9de39161c (patch) | |
tree | 79e484bd7fd38fe97c84fdb00a164534f43941e9 /server/helpers | |
parent | c5621bd23bce038671cd81149a0aa5e238558b67 (diff) | |
download | PeerTube-45f1bd72a08998c60a9dd68ff069cea9de39161c.tar.gz PeerTube-45f1bd72a08998c60a9dd68ff069cea9de39161c.tar.zst PeerTube-45f1bd72a08998c60a9dd68ff069cea9de39161c.zip |
Creating a user with an empty password will send an email to let him set his password (#2479)
* Creating a user with an empty password will send an email to let him set his password
* Consideration of Chocobozzz's comments
* Tips for optional password
* API documentation
* Fix circular imports
* Tests
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/users.ts | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index b4d5751e7..63673bee2 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts | |||
@@ -3,6 +3,7 @@ import { UserRole } from '../../../shared' | |||
3 | import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' | 3 | import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' |
4 | import { exists, isArray, isBooleanValid, isFileValid } from './misc' | 4 | import { exists, isArray, isBooleanValid, isFileValid } from './misc' |
5 | import { values } from 'lodash' | 5 | import { values } from 'lodash' |
6 | import { CONFIG } from '../../initializers/config' | ||
6 | 7 | ||
7 | const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS | 8 | const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS |
8 | 9 | ||
@@ -10,6 +11,14 @@ function isUserPasswordValid (value: string) { | |||
10 | return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.PASSWORD) | 11 | return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.PASSWORD) |
11 | } | 12 | } |
12 | 13 | ||
14 | function isUserPasswordValidOrEmpty (value: string) { | ||
15 | // Empty password is only possible if emailing is enabled. | ||
16 | if (value === '') { | ||
17 | return !!CONFIG.SMTP.HOSTNAME && !!CONFIG.SMTP.PORT | ||
18 | } | ||
19 | return isUserPasswordValid(value) | ||
20 | } | ||
21 | |||
13 | function isUserVideoQuotaValid (value: string) { | 22 | function isUserVideoQuotaValid (value: string) { |
14 | return exists(value) && validator.isInt(value + '', USERS_CONSTRAINTS_FIELDS.VIDEO_QUOTA) | 23 | return exists(value) && validator.isInt(value + '', USERS_CONSTRAINTS_FIELDS.VIDEO_QUOTA) |
15 | } | 24 | } |
@@ -103,6 +112,7 @@ export { | |||
103 | isUserVideosHistoryEnabledValid, | 112 | isUserVideosHistoryEnabledValid, |
104 | isUserBlockedValid, | 113 | isUserBlockedValid, |
105 | isUserPasswordValid, | 114 | isUserPasswordValid, |
115 | isUserPasswordValidOrEmpty, | ||
106 | isUserVideoLanguages, | 116 | isUserVideoLanguages, |
107 | isUserBlockedReasonValid, | 117 | isUserBlockedReasonValid, |
108 | isUserRoleValid, | 118 | isUserRoleValid, |