diff options
author | Chocobozzz <me@florianbigard.com> | 2019-10-25 13:54:32 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-10-25 13:54:32 +0200 |
commit | 4ce7eb71ba28a563336c07d10c182ff89461c72b (patch) | |
tree | 9350704adae97d145548d0b2cfdde3bd95b56dd5 /server/middlewares | |
parent | 45863288582a788def282ec25d437b1795510315 (diff) | |
download | PeerTube-4ce7eb71ba28a563336c07d10c182ff89461c72b.tar.gz PeerTube-4ce7eb71ba28a563336c07d10c182ff89461c72b.tar.zst PeerTube-4ce7eb71ba28a563336c07d10c182ff89461c72b.zip |
Add plugin hook on registration
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/users.ts | 17 |
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' | |||
35 | import { doesVideoExist } from '../../helpers/middlewares' | 35 | import { doesVideoExist } from '../../helpers/middlewares' |
36 | import { UserRole } from '../../../shared/models/users' | 36 | import { UserRole } from '../../../shared/models/users' |
37 | import { MUserDefault } from '@server/typings/models' | 37 | import { MUserDefault } from '@server/typings/models' |
38 | import { Hooks } from '@server/lib/plugins/hooks' | ||
39 | import { isLocalVideoAccepted } from '@server/lib/moderation' | ||
38 | 40 | ||
39 | const usersAddValidator = [ | 41 | const 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 | ||
281 | const ensureUserRegistrationAllowed = [ | 283 | const 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() |