- (req: express.Request, res: express.Response, next: express.NextFunction) => {
- // TODO: Add old password verification
- logger.debug('Checking usersUpdateMe parameters', { parameters: req.body })
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking usersUpdateMe parameters', { parameters: omit(req.body, 'password') })
+
+ if (req.body.password || req.body.email) {
+ if (!req.body.currentPassword) {
+ return res.status(400)
+ .json({ error: 'currentPassword parameter is missing.' })
+ .end()
+ }
+
+ const user = res.locals.oauth.token.User
+ if (await user.isPasswordMatch(req.body.currentPassword) !== true) {
+ return res.status(401)
+ .json({ error: 'currentPassword is invalid.' })
+ }
+ }
+
+ if (areValidationErrors(req, res)) return
+
+ return next()
+ }
+]
+
+const usersGetValidator = [
+ param('id').isInt().not().isEmpty().withMessage('Should have a valid id'),
+ query('withStats').optional().isBoolean().withMessage('Should have a valid stats flag'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking usersGet parameters', { parameters: req.params })
+
+ if (areValidationErrors(req, res)) return
+ if (!await checkUserIdExist(req.params.id, res, req.query.withStats)) return
+
+ return next()
+ }
+]
+
+const usersVideoRatingValidator = [
+ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking usersVideoRating parameters', { parameters: req.params })