diff options
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/users.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/server/middlewares/validators/users.js b/server/middlewares/validators/users.js index e540ab0d1..5defdf4e3 100644 --- a/server/middlewares/validators/users.js +++ b/server/middlewares/validators/users.js | |||
@@ -17,11 +17,20 @@ function usersAdd (req, res, next) { | |||
17 | req.checkBody('username', 'Should have a valid username').isUserUsernameValid() | 17 | req.checkBody('username', 'Should have a valid username').isUserUsernameValid() |
18 | req.checkBody('password', 'Should have a valid password').isUserPasswordValid() | 18 | req.checkBody('password', 'Should have a valid password').isUserPasswordValid() |
19 | 19 | ||
20 | // TODO: check we don't have already the same username | ||
21 | |||
22 | logger.debug('Checking usersAdd parameters', { parameters: req.body }) | 20 | logger.debug('Checking usersAdd parameters', { parameters: req.body }) |
23 | 21 | ||
24 | checkErrors(req, res, next) | 22 | checkErrors(req, res, function () { |
23 | User.loadByUsername(req.body.username, function (err, user) { | ||
24 | if (err) { | ||
25 | logger.error('Error in usersAdd request validator.', { error: err }) | ||
26 | return res.sendStatus(500) | ||
27 | } | ||
28 | |||
29 | if (user) return res.status(409).send('User already exists.') | ||
30 | |||
31 | next() | ||
32 | }) | ||
33 | }) | ||
25 | } | 34 | } |
26 | 35 | ||
27 | function usersRemove (req, res, next) { | 36 | function usersRemove (req, res, next) { |