-const usersRegisterValidator = [
- body('username')
- .custom(isUserUsernameValid),
- body('password')
- .custom(isUserPasswordValid),
- body('email')
- .isEmail(),
- body('displayName')
- .optional()
- .custom(isUserDisplayNameValid),
-
- body('channel.name')
- .optional()
- .custom(isVideoChannelUsernameValid),
- body('channel.displayName')
- .optional()
- .custom(isVideoChannelDisplayNameValid),
-
- async (req: express.Request, res: express.Response, next: express.NextFunction) => {
- if (areValidationErrors(req, res, { omitBodyLog: true })) 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()
- }
-]
-