aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-10-25 13:54:32 +0200
committerChocobozzz <me@florianbigard.com>2019-10-25 13:54:32 +0200
commit4ce7eb71ba28a563336c07d10c182ff89461c72b (patch)
tree9350704adae97d145548d0b2cfdde3bd95b56dd5 /server/middlewares/validators
parent45863288582a788def282ec25d437b1795510315 (diff)
downloadPeerTube-4ce7eb71ba28a563336c07d10c182ff89461c72b.tar.gz
PeerTube-4ce7eb71ba28a563336c07d10c182ff89461c72b.tar.zst
PeerTube-4ce7eb71ba28a563336c07d10c182ff89461c72b.zip
Add plugin hook on registration
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/users.ts17
1 files changed, 14 insertions, 3 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 804d1410e..8615de406 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -35,6 +35,8 @@ import { isThemeRegistered } from '../../lib/plugins/theme-utils'
35import { doesVideoExist } from '../../helpers/middlewares' 35import { doesVideoExist } from '../../helpers/middlewares'
36import { UserRole } from '../../../shared/models/users' 36import { UserRole } from '../../../shared/models/users'
37import { MUserDefault } from '@server/typings/models' 37import { MUserDefault } from '@server/typings/models'
38import { Hooks } from '@server/lib/plugins/hooks'
39import { isLocalVideoAccepted } from '@server/lib/moderation'
38 40
39const usersAddValidator = [ 41const usersAddValidator = [
40 body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), 42 body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'),
@@ -280,10 +282,19 @@ const usersVideoRatingValidator = [
280 282
281const ensureUserRegistrationAllowed = [ 283const ensureUserRegistrationAllowed = [
282 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 284 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
283 const allowed = await isSignupAllowed() 285 const allowedParams = {
284 if (allowed === false) { 286 body: req.body
287 }
288
289 const allowedResult = await Hooks.wrapPromiseFun(
290 isSignupAllowed,
291 allowedParams,
292 'filter:api.user.signup.allowed.result'
293 )
294
295 if (allowedResult.allowed === false) {
285 return res.status(403) 296 return res.status(403)
286 .json({ error: 'User registration is not enabled or user limit is reached.' }) 297 .json({ error: allowedResult.errorMessage || 'User registration is not enabled or user limit is reached.' })
287 } 298 }
288 299
289 return next() 300 return next()