diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-15 22:22:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-20 09:57:40 +0200 |
commit | 65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch) | |
tree | 4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/helpers/custom-validators/users.js | |
parent | d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff) | |
download | PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip |
First typescript iteration
Diffstat (limited to 'server/helpers/custom-validators/users.js')
-rw-r--r-- | server/helpers/custom-validators/users.js | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/server/helpers/custom-validators/users.js b/server/helpers/custom-validators/users.js deleted file mode 100644 index 2fc026e98..000000000 --- a/server/helpers/custom-validators/users.js +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const validator = require('express-validator').validator | ||
4 | const values = require('lodash/values') | ||
5 | |||
6 | const constants = require('../../initializers/constants') | ||
7 | const USERS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.USERS | ||
8 | |||
9 | const usersValidators = { | ||
10 | isUserPasswordValid, | ||
11 | isUserRoleValid, | ||
12 | isUserUsernameValid, | ||
13 | isUserDisplayNSFWValid | ||
14 | } | ||
15 | |||
16 | function isUserPasswordValid (value) { | ||
17 | return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.PASSWORD) | ||
18 | } | ||
19 | |||
20 | function isUserRoleValid (value) { | ||
21 | return values(constants.USER_ROLES).indexOf(value) !== -1 | ||
22 | } | ||
23 | |||
24 | function isUserUsernameValid (value) { | ||
25 | const max = USERS_CONSTRAINTS_FIELDS.USERNAME.max | ||
26 | const min = USERS_CONSTRAINTS_FIELDS.USERNAME.min | ||
27 | return validator.matches(value, new RegExp(`^[a-zA-Z0-9._]{${min},${max}}$`)) | ||
28 | } | ||
29 | |||
30 | function isUserDisplayNSFWValid (value) { | ||
31 | return validator.isBoolean(value) | ||
32 | } | ||
33 | |||
34 | // --------------------------------------------------------------------------- | ||
35 | |||
36 | module.exports = usersValidators | ||