From 2c2e90921646d223060e98d517fc8ac61c90eb9e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 9 Apr 2017 12:08:36 +0200 Subject: Server: add ability to register new user --- server/controllers/api/users.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'server/controllers/api') diff --git a/server/controllers/api/users.js b/server/controllers/api/users.js index 6b6c0774f..c7fe7bf85 100644 --- a/server/controllers/api/users.js +++ b/server/controllers/api/users.js @@ -44,6 +44,12 @@ router.post('/', createUser ) +router.post('/register', + ensureRegistrationEnabled, + validatorsUsers.usersAdd, + createUser +) + router.put('/:id', oAuth.authenticate, validatorsUsers.usersUpdate, @@ -66,6 +72,16 @@ module.exports = router // --------------------------------------------------------------------------- +function ensureRegistrationEnabled (req, res, next) { + const registrationEnabled = constants.CONFIG.SIGNUP.ENABLED + + if (registrationEnabled === true) { + return next() + } + + return res.status(400).send('User registration is not enabled.') +} + function createUser (req, res, next) { const user = db.User.build({ username: req.body.username, -- cgit v1.2.3