X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fusers.ts;h=a507afc5bf513ac9e6636236342c68f0658a9160;hb=b4055e1c23eeefb0c8a85a77f312b2827d98f483;hp=b4e09c9b7a794b05e14bc9ddf45f206558faca30;hpb=1f20622f2b087eaf8738d60fae00a44b9c558ca3;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index b4e09c9b7..a507afc5b 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -13,7 +13,7 @@ import { isUserNSFWPolicyValid, isUserPasswordValid, isUserRoleValid, - isUserUsernameValid, + isUserUsernameValid, isUserVideoLanguages, isUserVideoQuotaDailyValid, isUserVideoQuotaValid, isUserVideosHistoryEnabledValid @@ -27,8 +27,9 @@ 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' +import { isThemeNameValid } from '../../helpers/custom-validators/plugins' +import { isThemeRegistered } from '../../lib/plugins/theme-utils' const usersAddValidator = [ body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), @@ -178,21 +179,41 @@ 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('videoLanguages') + .optional() + .custom(isUserVideoLanguages).withMessage('Should have a valid video languages attribute'), body('videosHistoryEnabled') .optional() .custom(isUserVideosHistoryEnabledValid).withMessage('Should have a valid videos history enabled attribute'), + body('theme') + .optional() + .custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking usersUpdateMe parameters', { parameters: omit(req.body, 'password') }) - if (req.body.password) { + if (req.body.password || req.body.email) { if (!req.body.currentPassword) { return res.status(400) .send({ error: 'currentPassword parameter is missing.' }) @@ -329,8 +350,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 })