diff options
Diffstat (limited to 'server/middlewares/validators/users.ts')
-rw-r--r-- | server/middlewares/validators/users.ts | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index aff18be3d..76ecff884 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -56,7 +56,7 @@ const usersAddValidator = [ | |||
56 | body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), | 56 | body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), |
57 | body('password').custom(isUserPasswordValidOrEmpty).withMessage('Should have a valid password'), | 57 | body('password').custom(isUserPasswordValidOrEmpty).withMessage('Should have a valid password'), |
58 | body('email').isEmail().withMessage('Should have a valid email'), | 58 | body('email').isEmail().withMessage('Should have a valid email'), |
59 | body('channelName').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), | 59 | body('channelName').optional().custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), |
60 | body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), | 60 | body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), |
61 | body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), | 61 | body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), |
62 | body('role') | 62 | body('role') |
@@ -76,20 +76,17 @@ const usersAddValidator = [ | |||
76 | .json({ error: 'You can only create users (and not administrators or moderators)' }) | 76 | .json({ error: 'You can only create users (and not administrators or moderators)' }) |
77 | } | 77 | } |
78 | 78 | ||
79 | if (!req.body.channelName) { | 79 | if (req.body.channelName) { |
80 | return res.status(400) | 80 | if (req.body.channelName === req.body.username) { |
81 | .json({ error: 'Channel name is required.' }) | 81 | return res.status(400) |
82 | } | 82 | .json({ error: 'Channel name cannot be the same as user username.' }) |
83 | 83 | } | |
84 | if (req.body.channelName === req.body.username) { | ||
85 | return res.status(400) | ||
86 | .json({ error: 'Channel name cannot be the same as user username.' }) | ||
87 | } | ||
88 | 84 | ||
89 | const existing = await ActorModel.loadLocalByName(req.body.channelName) | 85 | const existing = await ActorModel.loadLocalByName(req.body.channelName) |
90 | if (existing) { | 86 | if (existing) { |
91 | return res.status(409) | 87 | return res.status(409) |
92 | .json({ error: `Channel with name ${req.body.channelName} already exists.` }) | 88 | .json({ error: `Channel with name ${req.body.channelName} already exists.` }) |
89 | } | ||
93 | } | 90 | } |
94 | 91 | ||
95 | return next() | 92 | return next() |