diff options
author | Chocobozzz <me@florianbigard.com> | 2022-08-03 10:10:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-03 10:10:26 +0200 |
commit | 0b6f531653a7a24f82ad65564479a70a9326301a (patch) | |
tree | f65d9c80e0e8ced86a8a9f7b00952bb04413a5b7 /server/lib/user.ts | |
parent | 35a0a924830d84f9ec28c129ec85cb1f45011fb8 (diff) | |
download | PeerTube-0b6f531653a7a24f82ad65564479a70a9326301a.tar.gz PeerTube-0b6f531653a7a24f82ad65564479a70a9326301a.tar.zst PeerTube-0b6f531653a7a24f82ad65564479a70a9326301a.zip |
Suffix external auth username on conflict
Diffstat (limited to 'server/lib/user.ts')
-rw-r--r-- | server/lib/user.ts | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts index f4ffae0e4..2e433da04 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts | |||
@@ -3,13 +3,11 @@ import { logger } from '@server/helpers/logger' | |||
3 | import { CONFIG } from '@server/initializers/config' | 3 | import { CONFIG } from '@server/initializers/config' |
4 | import { UserModel } from '@server/models/user/user' | 4 | import { UserModel } from '@server/models/user/user' |
5 | import { MActorDefault } from '@server/types/models/actor' | 5 | import { MActorDefault } from '@server/types/models/actor' |
6 | import { buildUUID } from '@shared/extra-utils' | ||
7 | import { ActivityPubActorType } from '../../shared/models/activitypub' | 6 | import { ActivityPubActorType } from '../../shared/models/activitypub' |
8 | import { UserAdminFlag, UserNotificationSetting, UserNotificationSettingValue, UserRole } from '../../shared/models/users' | 7 | import { UserAdminFlag, UserNotificationSetting, UserNotificationSettingValue, UserRole } from '../../shared/models/users' |
9 | import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants' | 8 | import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants' |
10 | import { sequelizeTypescript } from '../initializers/database' | 9 | import { sequelizeTypescript } from '../initializers/database' |
11 | import { AccountModel } from '../models/account/account' | 10 | import { AccountModel } from '../models/account/account' |
12 | import { ActorModel } from '../models/actor/actor' | ||
13 | import { UserNotificationSettingModel } from '../models/user/user-notification-setting' | 11 | import { UserNotificationSettingModel } from '../models/user/user-notification-setting' |
14 | import { MAccountDefault, MChannelActor } from '../types/models' | 12 | import { MAccountDefault, MChannelActor } from '../types/models' |
15 | import { MUser, MUserDefault, MUserId } from '../types/models/user' | 13 | import { MUser, MUserDefault, MUserId } from '../types/models/user' |
@@ -17,7 +15,7 @@ import { generateAndSaveActorKeys } from './activitypub/actors' | |||
17 | import { getLocalAccountActivityPubUrl } from './activitypub/url' | 15 | import { getLocalAccountActivityPubUrl } from './activitypub/url' |
18 | import { Emailer } from './emailer' | 16 | import { Emailer } from './emailer' |
19 | import { LiveQuotaStore } from './live/live-quota-store' | 17 | import { LiveQuotaStore } from './live/live-quota-store' |
20 | import { buildActorInstance } from './local-actor' | 18 | import { buildActorInstance, findAvailableLocalActorName } from './local-actor' |
21 | import { Redis } from './redis' | 19 | import { Redis } from './redis' |
22 | import { createLocalVideoChannel } from './video-channel' | 20 | import { createLocalVideoChannel } from './video-channel' |
23 | import { createWatchLaterPlaylist } from './video-playlist' | 21 | import { createWatchLaterPlaylist } from './video-playlist' |
@@ -71,6 +69,8 @@ function buildUser (options: { | |||
71 | }) | 69 | }) |
72 | } | 70 | } |
73 | 71 | ||
72 | // --------------------------------------------------------------------------- | ||
73 | |||
74 | async function createUserAccountAndChannelAndPlaylist (parameters: { | 74 | async function createUserAccountAndChannelAndPlaylist (parameters: { |
75 | userToCreate: MUser | 75 | userToCreate: MUser |
76 | userDisplayName?: string | 76 | userDisplayName?: string |
@@ -157,6 +157,8 @@ async function createApplicationActor (applicationId: number) { | |||
157 | return accountCreated | 157 | return accountCreated |
158 | } | 158 | } |
159 | 159 | ||
160 | // --------------------------------------------------------------------------- | ||
161 | |||
160 | async function sendVerifyUserEmail (user: MUser, isPendingEmail = false) { | 162 | async function sendVerifyUserEmail (user: MUser, isPendingEmail = false) { |
161 | const verificationString = await Redis.Instance.setVerifyEmailVerificationString(user.id) | 163 | const verificationString = await Redis.Instance.setVerifyEmailVerificationString(user.id) |
162 | let url = WEBSERVER.URL + '/verify-account/email?userId=' + user.id + '&verificationString=' + verificationString | 164 | let url = WEBSERVER.URL + '/verify-account/email?userId=' + user.id + '&verificationString=' + verificationString |
@@ -169,6 +171,8 @@ async function sendVerifyUserEmail (user: MUser, isPendingEmail = false) { | |||
169 | Emailer.Instance.addVerifyEmailJob(username, email, url) | 171 | Emailer.Instance.addVerifyEmailJob(username, email, url) |
170 | } | 172 | } |
171 | 173 | ||
174 | // --------------------------------------------------------------------------- | ||
175 | |||
172 | async function getOriginalVideoFileTotalFromUser (user: MUserId) { | 176 | async function getOriginalVideoFileTotalFromUser (user: MUserId) { |
173 | // Don't use sequelize because we need to use a sub query | 177 | // Don't use sequelize because we need to use a sub query |
174 | const query = UserModel.generateUserQuotaBaseSQL({ | 178 | const query = UserModel.generateUserQuotaBaseSQL({ |
@@ -263,12 +267,7 @@ function createDefaultUserNotificationSettings (user: MUserId, t: Transaction | | |||
263 | async function buildChannelAttributes (user: MUser, transaction?: Transaction, channelNames?: ChannelNames) { | 267 | async function buildChannelAttributes (user: MUser, transaction?: Transaction, channelNames?: ChannelNames) { |
264 | if (channelNames) return channelNames | 268 | if (channelNames) return channelNames |
265 | 269 | ||
266 | let channelName = user.username + '_channel' | 270 | const channelName = await findAvailableLocalActorName(user.username + '_channel', transaction) |
267 | |||
268 | // Conflict, generate uuid instead | ||
269 | const actor = await ActorModel.loadLocalByName(channelName, transaction) | ||
270 | if (actor) channelName = buildUUID() | ||
271 | |||
272 | const videoChannelDisplayName = `Main ${user.username} channel` | 271 | const videoChannelDisplayName = `Main ${user.username} channel` |
273 | 272 | ||
274 | return { | 273 | return { |