aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/users.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-21 11:54:22 +0200
committerChocobozzz <me@florianbigard.com>2018-06-21 11:54:22 +0200
commit2ef6a0635cb6be32ef6028fb76d1c8ba4a6f7109 (patch)
treee22ca1c1acc26a2597df3c4bc97e56b10905ca71 /server/middlewares/validators/users.ts
parent6387f320bf10f6b6c90b338bded8d7392dead18a (diff)
downloadPeerTube-2ef6a0635cb6be32ef6028fb76d1c8ba4a6f7109.tar.gz
PeerTube-2ef6a0635cb6be32ef6028fb76d1c8ba4a6f7109.tar.zst
PeerTube-2ef6a0635cb6be32ef6028fb76d1c8ba4a6f7109.zip
Do not create a user with the same username than another actor name
Diffstat (limited to 'server/middlewares/validators/users.ts')
-rw-r--r--server/middlewares/validators/users.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 4ad0e33da..8fbab4dd0 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -21,6 +21,7 @@ import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers'
21import { Redis } from '../../lib/redis' 21import { Redis } from '../../lib/redis'
22import { UserModel } from '../../models/account/user' 22import { UserModel } from '../../models/account/user'
23import { areValidationErrors } from './utils' 23import { areValidationErrors } from './utils'
24import { ActorModel } from '../../models/activitypub/actor'
24 25
25const usersAddValidator = [ 26const usersAddValidator = [
26 body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), 27 body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'),
@@ -271,6 +272,14 @@ async function checkUserNameOrEmailDoesNotAlreadyExist (username: string, email:
271 return false 272 return false
272 } 273 }
273 274
275 const actor = await ActorModel.loadLocalByName(username)
276 if (actor) {
277 res.status(409)
278 .send({ error: 'Another actor (account/channel) with this name already exists.' })
279 .end()
280 return false
281 }
282
274 return true 283 return true
275} 284}
276 285