From e4c556196d7b31111f17596840d2e1d60caa7dcb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 31 Jul 2016 20:58:43 +0200 Subject: Server: reorganize express validators --- server/helpers/custom-validators/users.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 server/helpers/custom-validators/users.js (limited to 'server/helpers/custom-validators/users.js') diff --git a/server/helpers/custom-validators/users.js b/server/helpers/custom-validators/users.js new file mode 100644 index 000000000..41e00d046 --- /dev/null +++ b/server/helpers/custom-validators/users.js @@ -0,0 +1,18 @@ +'use strict' + +const validator = require('express-validator').validator + +const constants = require('../../initializers/constants') +const USERS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.USERS + +const usersValidators = { + isUserUsernameValid: isUserUsernameValid +} + +function isUserUsernameValid (value) { + return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.USERNAME) +} + +// --------------------------------------------------------------------------- + +module.exports = usersValidators -- cgit v1.2.3 From 9bd2662976a75d3b03364cdbe6419e57c80f99a6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 4 Aug 2016 22:32:36 +0200 Subject: Implement user API (create, update, remove, list) --- server/helpers/custom-validators/users.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'server/helpers/custom-validators/users.js') 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 @@ 'use strict' const validator = require('express-validator').validator +const values = require('lodash/values') const constants = require('../../initializers/constants') const USERS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.USERS const usersValidators = { + isUserPasswordValid: isUserPasswordValid, + isUserRoleValid: isUserRoleValid, isUserUsernameValid: isUserUsernameValid } +function isUserPasswordValid (value) { + return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.PASSWORD) +} + +function isUserRoleValid (value) { + return values(constants.USER_ROLES).indexOf(value) !== -1 +} + function isUserUsernameValid (value) { - return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.USERNAME) + const max = USERS_CONSTRAINTS_FIELDS.USERNAME.max + const min = USERS_CONSTRAINTS_FIELDS.USERNAME.min + return validator.matches(value, new RegExp(`^[a-zA-Z0-9._]{${min},${max}}$`)) } // --------------------------------------------------------------------------- -- cgit v1.2.3 From c4403b29ad4db097af528a7f04eea07e0ed320d0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 2 Oct 2016 12:19:02 +0200 Subject: Server: remove useless hash affectations --- server/helpers/custom-validators/users.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'server/helpers/custom-validators/users.js') diff --git a/server/helpers/custom-validators/users.js b/server/helpers/custom-validators/users.js index 0e92989e5..88fa1592e 100644 --- a/server/helpers/custom-validators/users.js +++ b/server/helpers/custom-validators/users.js @@ -7,9 +7,9 @@ const constants = require('../../initializers/constants') const USERS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.USERS const usersValidators = { - isUserPasswordValid: isUserPasswordValid, - isUserRoleValid: isUserRoleValid, - isUserUsernameValid: isUserUsernameValid + isUserPasswordValid, + isUserRoleValid, + isUserUsernameValid } function isUserPasswordValid (value) { -- cgit v1.2.3