diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-21 11:54:22 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-21 11:54:22 +0200 |
commit | 2ef6a0635cb6be32ef6028fb76d1c8ba4a6f7109 (patch) | |
tree | e22ca1c1acc26a2597df3c4bc97e56b10905ca71 /server/middlewares/validators/users.ts | |
parent | 6387f320bf10f6b6c90b338bded8d7392dead18a (diff) | |
download | PeerTube-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.ts | 9 |
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' | |||
21 | import { Redis } from '../../lib/redis' | 21 | import { Redis } from '../../lib/redis' |
22 | import { UserModel } from '../../models/account/user' | 22 | import { UserModel } from '../../models/account/user' |
23 | import { areValidationErrors } from './utils' | 23 | import { areValidationErrors } from './utils' |
24 | import { ActorModel } from '../../models/activitypub/actor' | ||
24 | 25 | ||
25 | const usersAddValidator = [ | 26 | const 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 | ||