aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-05-20 13:53:51 +0200
committerChocobozzz <me@florianbigard.com>2020-05-20 13:53:51 +0200
commit745437e3ab402d5b8f85de6e9c09c3b6092e5904 (patch)
treef93e8cc7bdffe19b6c19251512b2fd31bfe4f41d /server/lib
parent148ab2f0f043a4c7cc28f9497cb6ae3819e8b838 (diff)
parentf33dc6ab2db1c733f09dcb039b8bf46c69854753 (diff)
downloadPeerTube-745437e3ab402d5b8f85de6e9c09c3b6092e5904.tar.gz
PeerTube-745437e3ab402d5b8f85de6e9c09c3b6092e5904.tar.zst
PeerTube-745437e3ab402d5b8f85de6e9c09c3b6092e5904.zip
Merge branch 'release/2.2.0' into develop
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/oauth-model.ts8
1 files changed, 8 insertions, 0 deletions
diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts
index e5ea4636e..db546efb1 100644
--- a/server/lib/oauth-model.ts
+++ b/server/lib/oauth-model.ts
@@ -14,6 +14,7 @@ import { UserAdminFlag } from '@shared/models/users/user-flag.model'
14import { createUserAccountAndChannelAndPlaylist } from './user' 14import { createUserAccountAndChannelAndPlaylist } from './user'
15import { UserRole } from '@shared/models/users/user-role' 15import { UserRole } from '@shared/models/users/user-role'
16import { PluginManager } from '@server/lib/plugins/plugin-manager' 16import { PluginManager } from '@server/lib/plugins/plugin-manager'
17import { ActorModel } from '@server/models/activitypub/actor'
17 18
18type TokenInfo = { accessToken: string, refreshToken: string, accessTokenExpiresAt: Date, refreshTokenExpiresAt: Date } 19type TokenInfo = { accessToken: string, refreshToken: string, accessTokenExpiresAt: Date, refreshTokenExpiresAt: Date }
19 20
@@ -109,6 +110,9 @@ async function getUser (usernameOrEmail?: string, password?: string) {
109 let user = await UserModel.loadByEmail(obj.user.email) 110 let user = await UserModel.loadByEmail(obj.user.email)
110 if (!user) user = await createUserFromExternal(obj.pluginName, obj.user) 111 if (!user) user = await createUserFromExternal(obj.pluginName, obj.user)
111 112
113 // Cannot create a user
114 if (!user) throw new AccessDeniedError('Cannot create such user: an actor with that name already exists.')
115
112 // If the user does not belongs to a plugin, it was created before its installation 116 // If the user does not belongs to a plugin, it was created before its installation
113 // Then we just go through a regular login process 117 // Then we just go through a regular login process
114 if (user.pluginAuth !== null) { 118 if (user.pluginAuth !== null) {
@@ -208,6 +212,10 @@ async function createUserFromExternal (pluginAuth: string, options: {
208 role: UserRole 212 role: UserRole
209 displayName: string 213 displayName: string
210}) { 214}) {
215 // Check an actor does not already exists with that name (removed user)
216 const actor = await ActorModel.loadLocalByName(options.username)
217 if (actor) return null
218
211 const userToCreate = new UserModel({ 219 const userToCreate = new UserModel({
212 username: options.username, 220 username: options.username,
213 password: null, 221 password: null,