Move ensureRegistrationEnabled to middlewares
authorChocobozzz <florian.bigard@gmail.com>
Sun, 25 Jun 2017 15:48:51 +0000 (17:48 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Sun, 25 Jun 2017 15:48:51 +0000 (17:48 +0200)
server/controllers/api/users.ts
server/middlewares/config.ts [new file with mode: 0644]
server/middlewares/index.ts

index 1e9e65689ea99b02a21762d46663bae4c5991b6d..ce15353eff73e6232b5773920ccdeda8d5d0ef01 100644 (file)
@@ -7,6 +7,7 @@ import { logger, getFormatedObjects } from '../../helpers'
 import {
   authenticate,
   ensureIsAdmin,
+  ensureUserRegistrationEnabled,
   usersAddValidator,
   usersUpdateValidator,
   usersRemoveValidator,
@@ -48,7 +49,7 @@ usersRouter.post('/',
 )
 
 usersRouter.post('/register',
-  ensureRegistrationEnabled,
+  ensureUserRegistrationEnabled,
   usersAddValidator,
   createUser
 )
@@ -77,16 +78,6 @@ export {
 
 // ---------------------------------------------------------------------------
 
-function ensureRegistrationEnabled (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const registrationEnabled = CONFIG.SIGNUP.ENABLED
-
-  if (registrationEnabled === true) {
-    return next()
-  }
-
-  return res.status(400).send('User registration is not enabled.')
-}
-
 function createUser (req: express.Request, res: express.Response, next: express.NextFunction) {
   const user = db.User.build({
     username: req.body.username,
diff --git a/server/middlewares/config.ts b/server/middlewares/config.ts
new file mode 100644 (file)
index 0000000..1481e66
--- /dev/null
@@ -0,0 +1,20 @@
+import 'express-validator'
+import * as express from 'express'
+
+import { CONFIG } from '../initializers'
+
+function ensureUserRegistrationEnabled (req: express.Request, res: express.Response, next: express.NextFunction) {
+  const registrationEnabled = CONFIG.SIGNUP.ENABLED
+
+  if (registrationEnabled === true) {
+    return next()
+  }
+
+  return res.status(400).send('User registration is not enabled.')
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+  ensureUserRegistrationEnabled
+}
index d71dd245265a6fbbebef6bf1acf2ef3188304a98..9a3f849a71285278ef26c5f8545fc34037432ceb 100644 (file)
@@ -1,5 +1,6 @@
 export * from './validators'
 export * from './admin'
+export * from './config'
 export * from './oauth'
 export * from './pagination'
 export * from './pods'