+ return next()
+ }
+]
+
+const usersUpdateMeValidator = [
+ body('displayName')
+ .optional()
+ .custom(isUserDisplayNameValid),
+ body('description')
+ .optional()
+ .custom(isUserDescriptionValid),
+ body('currentPassword')
+ .optional()
+ .custom(isUserPasswordValid),
+ body('password')
+ .optional()
+ .custom(isUserPasswordValid),
+ body('emailPublic')
+ .optional()
+ .custom(isUserEmailPublicValid),
+ body('email')
+ .optional()
+ .isEmail(),
+ body('nsfwPolicy')
+ .optional()
+ .custom(isUserNSFWPolicyValid),
+ body('autoPlayVideo')
+ .optional()
+ .custom(isUserAutoPlayVideoValid),
+ body('p2pEnabled')
+ .optional()
+ .custom(isUserP2PEnabledValid).withMessage('Should have a valid p2p enabled boolean'),
+ body('videoLanguages')
+ .optional()
+ .custom(isUserVideoLanguages),
+ body('videosHistoryEnabled')
+ .optional()
+ .custom(isUserVideosHistoryEnabledValid).withMessage('Should have a valid videos history enabled boolean'),
+ body('theme')
+ .optional()
+ .custom(v => isThemeNameValid(v) && isThemeRegistered(v)),
+
+ body('noInstanceConfigWarningModal')
+ .optional()
+ .custom(v => isUserNoModal(v)).withMessage('Should have a valid noInstanceConfigWarningModal boolean'),
+ body('noWelcomeModal')
+ .optional()
+ .custom(v => isUserNoModal(v)).withMessage('Should have a valid noWelcomeModal boolean'),
+ body('noAccountSetupWarningModal')
+ .optional()
+ .custom(v => isUserNoModal(v)).withMessage('Should have a valid noAccountSetupWarningModal boolean'),
+
+ body('autoPlayNextVideo')
+ .optional()
+ .custom(v => isUserAutoPlayNextVideoValid(v)).withMessage('Should have a valid autoPlayNextVideo boolean'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ const user = res.locals.oauth.token.User
+
+ if (req.body.password || req.body.email) {
+ if (user.pluginAuth !== null) {
+ return res.fail({ message: 'You cannot update your email or password that is associated with an external auth system.' })
+ }
+
+ if (!req.body.currentPassword) {
+ return res.fail({ message: 'currentPassword parameter is missing.' })
+ }
+
+ if (await user.isPasswordMatch(req.body.currentPassword) !== true) {
+ return res.fail({
+ status: HttpStatusCode.UNAUTHORIZED_401,
+ message: 'currentPassword is invalid.'
+ })
+ }