+ })
+ }
+]
+
+const usersUpdateValidator = [
+ param('id').isInt().not().isEmpty().withMessage('Should have a valid id'),
+ body('email').optional().isEmail().withMessage('Should have a valid email attribute'),
+ body('videoQuota').optional().custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking usersUpdate parameters', { parameters: req.body })
+
+ checkErrors(req, res, () => {
+ checkUserExists(req.params.id, res, next)
+ })
+ }
+]
+
+const usersUpdateMeValidator = [
+ body('password').optional().custom(isUserPasswordValid).withMessage('Should have a valid password'),
+ body('email').optional().isEmail().withMessage('Should have a valid email attribute'),
+ body('displayNSFW').optional().custom(isUserDisplayNSFWValid).withMessage('Should have a valid display Not Safe For Work attribute'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ // TODO: Add old password verification
+ logger.debug('Checking usersUpdateMe parameters', { parameters: req.body })
+
+ checkErrors(req, res, next)
+ }
+]
+
+const usersGetValidator = [
+ param('id').isInt().not().isEmpty().withMessage('Should have a valid id'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ checkErrors(req, res, () => {
+ checkUserExists(req.params.id, res, next)
+ })
+ }
+]
+
+const usersVideoRatingValidator = [
+ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking usersVideoRating parameters', { parameters: req.params })
+
+ checkErrors(req, res, () => {
+ let videoPromise: Promise<VideoInstance>
+
+ if (validator.isUUID(req.params.videoId)) {
+ videoPromise = db.Video.loadByUUID(req.params.videoId)
+ } else {
+ videoPromise = db.Video.load(req.params.videoId)
+ }
+
+ videoPromise
+ .then(video => {
+ if (!video) {
+ return res.status(404)
+ .json({ error: 'Video not found' })
+ .end()
+ }
+
+ return next()
+ })
+ .catch(err => {
+ logger.error('Error in user request validator.', err)
+ return res.sendStatus(500)
+ })
+ })
+ }
+]
+
+const ensureUserRegistrationAllowed = [
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ isSignupAllowed().then(allowed => {
+ if (allowed === false) {
+ return res.status(403)
+ .send({ error: 'User registration is not enabled or user limit is reached.' })
+ .end()
+ }
+
+ return next()
+ })
+ }
+]