-const usersRegisterValidator = [
- body('username').custom(isUserUsernameValid).withMessage('Should have a valid username'),
- body('password').custom(isUserPasswordValid).withMessage('Should have a valid password'),
- body('email').isEmail().withMessage('Should have a valid email'),
- body('displayName')
- .optional()
- .custom(isUserDisplayNameValid).withMessage('Should have a valid display name'),
-
- body('channel.name')
- .optional()
- .custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'),
- body('channel.displayName')
- .optional()
- .custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'),
-
- async (req: express.Request, res: express.Response, next: express.NextFunction) => {
- logger.debug('Checking usersRegister parameters', { parameters: omit(req.body, 'password') })
-
- if (areValidationErrors(req, res)) return
- if (!await checkUserNameOrEmailDoesNotAlreadyExist(req.body.username, req.body.email, res)) return
-
- const body: UserRegister = req.body
- if (body.channel) {
- if (!body.channel.name || !body.channel.displayName) {
- return res.fail({ message: 'Channel is optional but if you specify it, channel.name and channel.displayName are required.' })
- }
-
- if (body.channel.name === body.username) {
- return res.fail({ message: 'Channel name cannot be the same as user username.' })
- }
-
- const existing = await ActorModel.loadLocalByName(body.channel.name)
- if (existing) {
- return res.fail({
- status: HttpStatusCode.CONFLICT_409,
- message: `Channel with name ${body.channel.name} already exists.`
- })
- }
- }
-
- return next()
- }
-]
-