aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/users.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/users.js')
-rw-r--r--server/helpers/custom-validators/users.js15
1 files changed, 14 insertions, 1 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
3const validator = require('express-validator').validator 3const validator = require('express-validator').validator
4const values = require('lodash/values')
4 5
5const constants = require('../../initializers/constants') 6const constants = require('../../initializers/constants')
6const USERS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.USERS 7const USERS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.USERS
7 8
8const usersValidators = { 9const usersValidators = {
10 isUserPasswordValid: isUserPasswordValid,
11 isUserRoleValid: isUserRoleValid,
9 isUserUsernameValid: isUserUsernameValid 12 isUserUsernameValid: isUserUsernameValid
10} 13}
11 14
15function isUserPasswordValid (value) {
16 return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.PASSWORD)
17}
18
19function isUserRoleValid (value) {
20 return values(constants.USER_ROLES).indexOf(value) !== -1
21}
22
12function isUserUsernameValid (value) { 23function 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// ---------------------------------------------------------------------------