aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/users.ts19
1 files changed, 17 insertions, 2 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 247b704c4..4ad0e33da 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -16,8 +16,8 @@ import {
16} from '../../helpers/custom-validators/users' 16} from '../../helpers/custom-validators/users'
17import { isVideoExist } from '../../helpers/custom-validators/videos' 17import { isVideoExist } from '../../helpers/custom-validators/videos'
18import { logger } from '../../helpers/logger' 18import { logger } from '../../helpers/logger'
19import { isSignupAllowed } from '../../helpers/utils' 19import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/utils'
20import { CONSTRAINTS_FIELDS } from '../../initializers' 20import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers'
21import { Redis } from '../../lib/redis' 21import { Redis } from '../../lib/redis'
22import { UserModel } from '../../models/account/user' 22import { UserModel } from '../../models/account/user'
23import { areValidationErrors } from './utils' 23import { areValidationErrors } from './utils'
@@ -177,6 +177,20 @@ const ensureUserRegistrationAllowed = [
177 } 177 }
178] 178]
179 179
180const ensureUserRegistrationAllowedForIP = [
181 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
182 const allowed = isSignupAllowedForCurrentIP(req.ip)
183
184 if (allowed === false) {
185 return res.status(403)
186 .send({ error: 'You are not on a network authorized for registration.' })
187 .end()
188 }
189
190 return next()
191 }
192]
193
180const usersAskResetPasswordValidator = [ 194const usersAskResetPasswordValidator = [
181 body('email').isEmail().not().isEmpty().withMessage('Should have a valid email'), 195 body('email').isEmail().not().isEmpty().withMessage('Should have a valid email'),
182 196
@@ -230,6 +244,7 @@ export {
230 usersUpdateMeValidator, 244 usersUpdateMeValidator,
231 usersVideoRatingValidator, 245 usersVideoRatingValidator,
232 ensureUserRegistrationAllowed, 246 ensureUserRegistrationAllowed,
247 ensureUserRegistrationAllowedForIP,
233 usersGetValidator, 248 usersGetValidator,
234 usersUpdateMyAvatarValidator, 249 usersUpdateMyAvatarValidator,
235 usersAskResetPasswordValidator, 250 usersAskResetPasswordValidator,