From: Chocobozzz Date: Sun, 25 Jun 2017 15:48:51 +0000 (+0200) Subject: Move ensureRegistrationEnabled to middlewares X-Git-Tag: v0.0.1-alpha~384 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ba44fa19531186944fef3e9da34f5e91f0c0dedb;p=oweals%2Fpeertube.git Move ensureRegistrationEnabled to middlewares --- 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' 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 index 000000000..1481e66cc --- /dev/null +++ b/server/middlewares/config.ts @@ -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 +} 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 @@ export * from './validators' export * from './admin' +export * from './config' export * from './oauth' export * from './pagination' export * from './pods'