]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/oauth-model.ts
Add ability to override client assets : logo - favicon - PWA icons - PWA manifest...
[github/Chocobozzz/PeerTube.git] / server / lib / oauth-model.ts
index e5ea4636ee8b2e83dfc3c18afc74a29da4e9a3c8..3273c6c2d485bacc345db5da47afe1f6ea5be024 100644 (file)
@@ -8,12 +8,13 @@ import { LRU_CACHE } from '../initializers/constants'
 import { Transaction } from 'sequelize'
 import { CONFIG } from '../initializers/config'
 import * as LRUCache from 'lru-cache'
-import { MOAuthTokenUser } from '@server/typings/models/oauth/oauth-token'
-import { MUser } from '@server/typings/models/user/user'
+import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token'
+import { MUser } from '@server/types/models/user/user'
 import { UserAdminFlag } from '@shared/models/users/user-flag.model'
 import { createUserAccountAndChannelAndPlaylist } from './user'
 import { UserRole } from '@shared/models/users/user-role'
 import { PluginManager } from '@server/lib/plugins/plugin-manager'
+import { ActorModel } from '@server/models/activitypub/actor'
 
 type TokenInfo = { accessToken: string, refreshToken: string, accessTokenExpiresAt: Date, refreshTokenExpiresAt: Date }
 
@@ -109,6 +110,9 @@ async function getUser (usernameOrEmail?: string, password?: string) {
     let user = await UserModel.loadByEmail(obj.user.email)
     if (!user) user = await createUserFromExternal(obj.pluginName, obj.user)
 
+    // Cannot create a user
+    if (!user) throw new AccessDeniedError('Cannot create such user: an actor with that name already exists.')
+
     // If the user does not belongs to a plugin, it was created before its installation
     // Then we just go through a regular login process
     if (user.pluginAuth !== null) {
@@ -208,6 +212,10 @@ async function createUserFromExternal (pluginAuth: string, options: {
   role: UserRole
   displayName: string
 }) {
+  // Check an actor does not already exists with that name (removed user)
+  const actor = await ActorModel.loadLocalByName(options.username)
+  if (actor) return null
+
   const userToCreate = new UserModel({
     username: options.username,
     password: null,