diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-04-09 12:08:36 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-04-09 12:08:36 +0200 |
commit | 2c2e90921646d223060e98d517fc8ac61c90eb9e (patch) | |
tree | cc36bfa79f0809e8c9602492788ef95b3521e003 /server/controllers/api/users.js | |
parent | db216afd980846c418a4ebab8190c3ead561dfc1 (diff) | |
download | PeerTube-2c2e90921646d223060e98d517fc8ac61c90eb9e.tar.gz PeerTube-2c2e90921646d223060e98d517fc8ac61c90eb9e.tar.zst PeerTube-2c2e90921646d223060e98d517fc8ac61c90eb9e.zip |
Server: add ability to register new user
Diffstat (limited to 'server/controllers/api/users.js')
-rw-r--r-- | server/controllers/api/users.js | 16 |
1 files changed, 16 insertions, 0 deletions
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('/', | |||
44 | createUser | 44 | createUser |
45 | ) | 45 | ) |
46 | 46 | ||
47 | router.post('/register', | ||
48 | ensureRegistrationEnabled, | ||
49 | validatorsUsers.usersAdd, | ||
50 | createUser | ||
51 | ) | ||
52 | |||
47 | router.put('/:id', | 53 | router.put('/:id', |
48 | oAuth.authenticate, | 54 | oAuth.authenticate, |
49 | validatorsUsers.usersUpdate, | 55 | validatorsUsers.usersUpdate, |
@@ -66,6 +72,16 @@ module.exports = router | |||
66 | 72 | ||
67 | // --------------------------------------------------------------------------- | 73 | // --------------------------------------------------------------------------- |
68 | 74 | ||
75 | function ensureRegistrationEnabled (req, res, next) { | ||
76 | const registrationEnabled = constants.CONFIG.SIGNUP.ENABLED | ||
77 | |||
78 | if (registrationEnabled === true) { | ||
79 | return next() | ||
80 | } | ||
81 | |||
82 | return res.status(400).send('User registration is not enabled.') | ||
83 | } | ||
84 | |||
69 | function createUser (req, res, next) { | 85 | function createUser (req, res, next) { |
70 | const user = db.User.build({ | 86 | const user = db.User.build({ |
71 | username: req.body.username, | 87 | username: req.body.username, |