diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/users.ts | 13 | ||||
-rw-r--r-- | server/middlewares/config.ts | 20 | ||||
-rw-r--r-- | server/middlewares/index.ts | 1 |
3 files changed, 23 insertions, 11 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 1e9e65689..ce15353ef 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -7,6 +7,7 @@ import { logger, getFormatedObjects } from '../../helpers' | |||
7 | import { | 7 | import { |
8 | authenticate, | 8 | authenticate, |
9 | ensureIsAdmin, | 9 | ensureIsAdmin, |
10 | ensureUserRegistrationEnabled, | ||
10 | usersAddValidator, | 11 | usersAddValidator, |
11 | usersUpdateValidator, | 12 | usersUpdateValidator, |
12 | usersRemoveValidator, | 13 | usersRemoveValidator, |
@@ -48,7 +49,7 @@ usersRouter.post('/', | |||
48 | ) | 49 | ) |
49 | 50 | ||
50 | usersRouter.post('/register', | 51 | usersRouter.post('/register', |
51 | ensureRegistrationEnabled, | 52 | ensureUserRegistrationEnabled, |
52 | usersAddValidator, | 53 | usersAddValidator, |
53 | createUser | 54 | createUser |
54 | ) | 55 | ) |
@@ -77,16 +78,6 @@ export { | |||
77 | 78 | ||
78 | // --------------------------------------------------------------------------- | 79 | // --------------------------------------------------------------------------- |
79 | 80 | ||
80 | function ensureRegistrationEnabled (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
81 | const registrationEnabled = CONFIG.SIGNUP.ENABLED | ||
82 | |||
83 | if (registrationEnabled === true) { | ||
84 | return next() | ||
85 | } | ||
86 | |||
87 | return res.status(400).send('User registration is not enabled.') | ||
88 | } | ||
89 | |||
90 | function createUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 81 | function createUser (req: express.Request, res: express.Response, next: express.NextFunction) { |
91 | const user = db.User.build({ | 82 | const user = db.User.build({ |
92 | username: req.body.username, | 83 | username: req.body.username, |
diff --git a/server/middlewares/config.ts b/server/middlewares/config.ts new file mode 100644 index 000000000..1481e66cc --- /dev/null +++ b/server/middlewares/config.ts | |||
@@ -0,0 +1,20 @@ | |||
1 | import 'express-validator' | ||
2 | import * as express from 'express' | ||
3 | |||
4 | import { CONFIG } from '../initializers' | ||
5 | |||
6 | function ensureUserRegistrationEnabled (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
7 | const registrationEnabled = CONFIG.SIGNUP.ENABLED | ||
8 | |||
9 | if (registrationEnabled === true) { | ||
10 | return next() | ||
11 | } | ||
12 | |||
13 | return res.status(400).send('User registration is not enabled.') | ||
14 | } | ||
15 | |||
16 | // --------------------------------------------------------------------------- | ||
17 | |||
18 | export { | ||
19 | ensureUserRegistrationEnabled | ||
20 | } | ||
diff --git a/server/middlewares/index.ts b/server/middlewares/index.ts index d71dd2452..9a3f849a7 100644 --- a/server/middlewares/index.ts +++ b/server/middlewares/index.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | export * from './validators' | 1 | export * from './validators' |
2 | export * from './admin' | 2 | export * from './admin' |
3 | export * from './config' | ||
3 | export * from './oauth' | 4 | export * from './oauth' |
4 | export * from './pagination' | 5 | export * from './pagination' |
5 | export * from './pods' | 6 | export * from './pods' |