mirror of https://github.com/Chocobozzz/PeerTube
Move ensureRegistrationEnabled to middlewares
parent
0a381679e0
commit
ba44fa1953
|
@ -7,6 +7,7 @@ import { logger, getFormatedObjects } from '../../helpers'
|
||||||
import {
|
import {
|
||||||
authenticate,
|
authenticate,
|
||||||
ensureIsAdmin,
|
ensureIsAdmin,
|
||||||
|
ensureUserRegistrationEnabled,
|
||||||
usersAddValidator,
|
usersAddValidator,
|
||||||
usersUpdateValidator,
|
usersUpdateValidator,
|
||||||
usersRemoveValidator,
|
usersRemoveValidator,
|
||||||
|
@ -48,7 +49,7 @@ usersRouter.post('/',
|
||||||
)
|
)
|
||||||
|
|
||||||
usersRouter.post('/register',
|
usersRouter.post('/register',
|
||||||
ensureRegistrationEnabled,
|
ensureUserRegistrationEnabled,
|
||||||
usersAddValidator,
|
usersAddValidator,
|
||||||
createUser
|
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) {
|
function createUser (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||||
const user = db.User.build({
|
const user = db.User.build({
|
||||||
username: req.body.username,
|
username: req.body.username,
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
export * from './validators'
|
export * from './validators'
|
||||||
export * from './admin'
|
export * from './admin'
|
||||||
|
export * from './config'
|
||||||
export * from './oauth'
|
export * from './oauth'
|
||||||
export * from './pagination'
|
export * from './pagination'
|
||||||
export * from './pods'
|
export * from './pods'
|
||||||
|
|
Loading…
Reference in New Issue