diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-04 10:57:36 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-04 10:57:36 +0100 |
commit | d3d3deaa7aae49d6d949aebcba015af75d292ccc (patch) | |
tree | 42e487810f5b7362c28f744371d160a4effc7566 /server/lib/auth | |
parent | 90370f7cc85ee4b45eb0d1bafed2d9d68610df9f (diff) | |
download | PeerTube-d3d3deaa7aae49d6d949aebcba015af75d292ccc.tar.gz PeerTube-d3d3deaa7aae49d6d949aebcba015af75d292ccc.tar.zst PeerTube-d3d3deaa7aae49d6d949aebcba015af75d292ccc.zip |
Refactor user build and express file middlewares
Diffstat (limited to 'server/lib/auth')
-rw-r--r-- | server/lib/auth/oauth-model.ts | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/server/lib/auth/oauth-model.ts b/server/lib/auth/oauth-model.ts index 5d68f44e9..910fdeec1 100644 --- a/server/lib/auth/oauth-model.ts +++ b/server/lib/auth/oauth-model.ts | |||
@@ -5,14 +5,14 @@ import { ActorModel } from '@server/models/actor/actor' | |||
5 | import { MOAuthClient } from '@server/types/models' | 5 | import { MOAuthClient } from '@server/types/models' |
6 | import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token' | 6 | import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token' |
7 | import { MUser } from '@server/types/models/user/user' | 7 | import { MUser } from '@server/types/models/user/user' |
8 | import { UserAdminFlag } from '@shared/models/users/user-flag.model' | 8 | import { pick } from '@shared/core-utils' |
9 | import { UserRole } from '@shared/models/users/user-role' | 9 | import { UserRole } from '@shared/models/users/user-role' |
10 | import { logger } from '../../helpers/logger' | 10 | import { logger } from '../../helpers/logger' |
11 | import { CONFIG } from '../../initializers/config' | 11 | import { CONFIG } from '../../initializers/config' |
12 | import { OAuthClientModel } from '../../models/oauth/oauth-client' | 12 | import { OAuthClientModel } from '../../models/oauth/oauth-client' |
13 | import { OAuthTokenModel } from '../../models/oauth/oauth-token' | 13 | import { OAuthTokenModel } from '../../models/oauth/oauth-token' |
14 | import { UserModel } from '../../models/user/user' | 14 | import { UserModel } from '../../models/user/user' |
15 | import { createUserAccountAndChannelAndPlaylist } from '../user' | 15 | import { buildUser, createUserAccountAndChannelAndPlaylist } from '../user' |
16 | import { TokensCache } from './tokens-cache' | 16 | import { TokensCache } from './tokens-cache' |
17 | 17 | ||
18 | type TokenInfo = { | 18 | type TokenInfo = { |
@@ -229,19 +229,13 @@ async function createUserFromExternal (pluginAuth: string, options: { | |||
229 | const actor = await ActorModel.loadLocalByName(options.username) | 229 | const actor = await ActorModel.loadLocalByName(options.username) |
230 | if (actor) return null | 230 | if (actor) return null |
231 | 231 | ||
232 | const userToCreate = new UserModel({ | 232 | const userToCreate = buildUser({ |
233 | username: options.username, | 233 | ...pick(options, [ 'username', 'email', 'role' ]), |
234 | |||
235 | emailVerified: null, | ||
234 | password: null, | 236 | password: null, |
235 | email: options.email, | ||
236 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, | ||
237 | p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED, | ||
238 | autoPlayVideo: true, | ||
239 | role: options.role, | ||
240 | videoQuota: CONFIG.USER.VIDEO_QUOTA, | ||
241 | videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY, | ||
242 | adminFlags: UserAdminFlag.NONE, | ||
243 | pluginAuth | 237 | pluginAuth |
244 | }) as MUser | 238 | }) |
245 | 239 | ||
246 | const { user } = await createUserAccountAndChannelAndPlaylist({ | 240 | const { user } = await createUserAccountAndChannelAndPlaylist({ |
247 | userToCreate, | 241 | userToCreate, |