diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-08-04 22:32:36 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-08-04 22:33:38 +0200 |
commit | 9bd2662976a75d3b03364cdbe6419e57c80f99a6 (patch) | |
tree | 0b5289660f843a8ba7f13aa79d458f53c94b36d9 /server/helpers/custom-validators | |
parent | e4c556196d7b31111f17596840d2e1d60caa7dcb (diff) | |
download | PeerTube-9bd2662976a75d3b03364cdbe6419e57c80f99a6.tar.gz PeerTube-9bd2662976a75d3b03364cdbe6419e57c80f99a6.tar.zst PeerTube-9bd2662976a75d3b03364cdbe6419e57c80f99a6.zip |
Implement user API (create, update, remove, list)
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/users.js | 15 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.js | 2 |
2 files changed, 15 insertions, 2 deletions
diff --git a/server/helpers/custom-validators/users.js b/server/helpers/custom-validators/users.js index 41e00d046..0e92989e5 100644 --- a/server/helpers/custom-validators/users.js +++ b/server/helpers/custom-validators/users.js | |||
@@ -1,16 +1,29 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const validator = require('express-validator').validator | 3 | const validator = require('express-validator').validator |
4 | const values = require('lodash/values') | ||
4 | 5 | ||
5 | const constants = require('../../initializers/constants') | 6 | const constants = require('../../initializers/constants') |
6 | const USERS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.USERS | 7 | const USERS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.USERS |
7 | 8 | ||
8 | const usersValidators = { | 9 | const usersValidators = { |
10 | isUserPasswordValid: isUserPasswordValid, | ||
11 | isUserRoleValid: isUserRoleValid, | ||
9 | isUserUsernameValid: isUserUsernameValid | 12 | isUserUsernameValid: isUserUsernameValid |
10 | } | 13 | } |
11 | 14 | ||
15 | function isUserPasswordValid (value) { | ||
16 | return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.PASSWORD) | ||
17 | } | ||
18 | |||
19 | function isUserRoleValid (value) { | ||
20 | return values(constants.USER_ROLES).indexOf(value) !== -1 | ||
21 | } | ||
22 | |||
12 | function isUserUsernameValid (value) { | 23 | function isUserUsernameValid (value) { |
13 | return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.USERNAME) | 24 | const max = USERS_CONSTRAINTS_FIELDS.USERNAME.max |
25 | const min = USERS_CONSTRAINTS_FIELDS.USERNAME.min | ||
26 | return validator.matches(value, new RegExp(`^[a-zA-Z0-9._]{${min},${max}}$`)) | ||
14 | } | 27 | } |
15 | 28 | ||
16 | // --------------------------------------------------------------------------- | 29 | // --------------------------------------------------------------------------- |
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js index 39a19cbd7..cffa973f8 100644 --- a/server/helpers/custom-validators/videos.js +++ b/server/helpers/custom-validators/videos.js | |||
@@ -45,7 +45,7 @@ function isEachRemoteVideosValid (requests) { | |||
45 | } | 45 | } |
46 | 46 | ||
47 | function isVideoAuthorValid (value) { | 47 | function isVideoAuthorValid (value) { |
48 | return usersValidators.isUserUsernameValid(usersValidators) | 48 | return usersValidators.isUserUsernameValid(value) |
49 | } | 49 | } |
50 | 50 | ||
51 | function isVideoDateValid (value) { | 51 | function isVideoDateValid (value) { |