From d1ab89deb79f70c439b58750d044d9cadf1194e5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 Jun 2019 11:54:33 +0200 Subject: Handle email update on server --- server/middlewares/validators/users.ts | 39 +++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'server/middlewares/validators/users.ts') diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index b4e09c9b7..a4d4ae46d 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -27,7 +27,6 @@ import { areValidationErrors } from './utils' import { ActorModel } from '../../models/activitypub/actor' import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' import { isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' -import { UserCreate } from '../../../shared/models/users' import { UserRegister } from '../../../shared/models/users/user-register.model' const usersAddValidator = [ @@ -178,13 +177,27 @@ const usersUpdateValidator = [ ] const usersUpdateMeValidator = [ - body('displayName').optional().custom(isUserDisplayNameValid).withMessage('Should have a valid display name'), - body('description').optional().custom(isUserDescriptionValid).withMessage('Should have a valid description'), - body('currentPassword').optional().custom(isUserPasswordValid).withMessage('Should have a valid current password'), - body('password').optional().custom(isUserPasswordValid).withMessage('Should have a valid password'), - body('email').optional().isEmail().withMessage('Should have a valid email attribute'), - body('nsfwPolicy').optional().custom(isUserNSFWPolicyValid).withMessage('Should have a valid display Not Safe For Work policy'), - body('autoPlayVideo').optional().custom(isUserAutoPlayVideoValid).withMessage('Should have a valid automatically plays video attribute'), + body('displayName') + .optional() + .custom(isUserDisplayNameValid).withMessage('Should have a valid display name'), + body('description') + .optional() + .custom(isUserDescriptionValid).withMessage('Should have a valid description'), + body('currentPassword') + .optional() + .custom(isUserPasswordValid).withMessage('Should have a valid current password'), + body('password') + .optional() + .custom(isUserPasswordValid).withMessage('Should have a valid password'), + body('email') + .optional() + .isEmail().withMessage('Should have a valid email attribute'), + body('nsfwPolicy') + .optional() + .custom(isUserNSFWPolicyValid).withMessage('Should have a valid display Not Safe For Work policy'), + body('autoPlayVideo') + .optional() + .custom(isUserAutoPlayVideoValid).withMessage('Should have a valid automatically plays video attribute'), body('videosHistoryEnabled') .optional() .custom(isUserVideosHistoryEnabledValid).withMessage('Should have a valid videos history enabled attribute'), @@ -329,8 +342,14 @@ const usersAskSendVerifyEmailValidator = [ ] const usersVerifyEmailValidator = [ - param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), - body('verificationString').not().isEmpty().withMessage('Should have a valid verification string'), + param('id') + .isInt().not().isEmpty().withMessage('Should have a valid id'), + + body('verificationString') + .not().isEmpty().withMessage('Should have a valid verification string'), + body('isPendingEmail') + .optional() + .toBoolean(), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params }) -- cgit v1.2.3