aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/users.ts
diff options
context:
space:
mode:
authorkimsible <kimsible@users.noreply.github.com>2020-07-29 16:23:42 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-08-11 08:46:35 +0200
commit4e68fc8605bff02f4c79deafc24cb39779802d0d (patch)
treea1c1b1eea852f44e06ab7b859915922d7e1442ef /server/middlewares/validators/users.ts
parent3d215dc5f978b58b8a6d0154c3feae27f13f1600 (diff)
downloadPeerTube-4e68fc8605bff02f4c79deafc24cb39779802d0d.tar.gz
PeerTube-4e68fc8605bff02f4c79deafc24cb39779802d0d.tar.zst
PeerTube-4e68fc8605bff02f4c79deafc24cb39779802d0d.zip
Add validator channelName for create-user api
Diffstat (limited to 'server/middlewares/validators/users.ts')
-rw-r--r--server/middlewares/validators/users.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 423da9bc0..aff18be3d 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -56,6 +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('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), 60 body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'),
60 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'),
61 body('role') 62 body('role')
@@ -75,6 +76,22 @@ const usersAddValidator = [
75 .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)' })
76 } 77 }
77 78
79 if (!req.body.channelName) {
80 return res.status(400)
81 .json({ error: 'Channel name is required.' })
82 }
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
89 const existing = await ActorModel.loadLocalByName(req.body.channelName)
90 if (existing) {
91 return res.status(409)
92 .json({ error: `Channel with name ${req.body.channelName} already exists.` })
93 }
94
78 return next() 95 return next()
79 } 96 }
80] 97]