aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/user.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/user.ts')
-rw-r--r--server/lib/user.ts57
1 files changed, 53 insertions, 4 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts
index 3f7499296..ea755f4be 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -1,9 +1,11 @@
1import { Transaction } from 'sequelize/types' 1import { Transaction } from 'sequelize/types'
2import { logger } from '@server/helpers/logger'
3import { CONFIG } from '@server/initializers/config'
2import { UserModel } from '@server/models/user/user' 4import { UserModel } from '@server/models/user/user'
3import { MActorDefault } from '@server/types/models/actor' 5import { MActorDefault } from '@server/types/models/actor'
4import { buildUUID } from '@shared/extra-utils' 6import { buildUUID } from '@shared/extra-utils'
5import { ActivityPubActorType } from '../../shared/models/activitypub' 7import { ActivityPubActorType } from '../../shared/models/activitypub'
6import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users' 8import { UserAdminFlag, UserNotificationSetting, UserNotificationSettingValue, UserRole } from '../../shared/models/users'
7import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants' 9import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants'
8import { sequelizeTypescript } from '../initializers/database' 10import { sequelizeTypescript } from '../initializers/database'
9import { AccountModel } from '../models/account/account' 11import { AccountModel } from '../models/account/account'
@@ -19,10 +21,56 @@ import { buildActorInstance } from './local-actor'
19import { Redis } from './redis' 21import { Redis } from './redis'
20import { createLocalVideoChannel } from './video-channel' 22import { createLocalVideoChannel } from './video-channel'
21import { createWatchLaterPlaylist } from './video-playlist' 23import { createWatchLaterPlaylist } from './video-playlist'
22import { logger } from '@server/helpers/logger'
23 24
24type ChannelNames = { name: string, displayName: string } 25type ChannelNames = { name: string, displayName: string }
25 26
27function buildUser (options: {
28 username: string
29 password: string
30 email: string
31
32 role?: UserRole // Default to UserRole.User
33 adminFlags?: UserAdminFlag // Default to UserAdminFlag.NONE
34
35 emailVerified: boolean | null
36
37 videoQuota?: number // Default to CONFIG.USER.VIDEO_QUOTA
38 videoQuotaDaily?: number // Default to CONFIG.USER.VIDEO_QUOTA_DAILY
39
40 pluginAuth?: string
41}): MUser {
42 const {
43 username,
44 password,
45 email,
46 role = UserRole.USER,
47 emailVerified,
48 videoQuota = CONFIG.USER.VIDEO_QUOTA,
49 videoQuotaDaily = CONFIG.USER.VIDEO_QUOTA_DAILY,
50 adminFlags = UserAdminFlag.NONE,
51 pluginAuth
52 } = options
53
54 return new UserModel({
55 username,
56 password,
57 email,
58
59 nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
60 p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED,
61 autoPlayVideo: true,
62
63 role,
64 emailVerified,
65 adminFlags,
66
67 videoQuota: videoQuota,
68 videoQuotaDaily: videoQuotaDaily,
69
70 pluginAuth
71 })
72}
73
26async function createUserAccountAndChannelAndPlaylist (parameters: { 74async function createUserAccountAndChannelAndPlaylist (parameters: {
27 userToCreate: MUser 75 userToCreate: MUser
28 userDisplayName?: string 76 userDisplayName?: string
@@ -118,7 +166,7 @@ async function sendVerifyUserEmail (user: MUser, isPendingEmail = false) {
118 const email = isPendingEmail ? user.pendingEmail : user.email 166 const email = isPendingEmail ? user.pendingEmail : user.email
119 const username = user.username 167 const username = user.username
120 168
121 await Emailer.Instance.addVerifyEmailJob(username, email, url) 169 Emailer.Instance.addVerifyEmailJob(username, email, url)
122} 170}
123 171
124async function getOriginalVideoFileTotalFromUser (user: MUserId) { 172async function getOriginalVideoFileTotalFromUser (user: MUserId) {
@@ -180,7 +228,8 @@ export {
180 createUserAccountAndChannelAndPlaylist, 228 createUserAccountAndChannelAndPlaylist,
181 createLocalAccountWithoutKeys, 229 createLocalAccountWithoutKeys,
182 sendVerifyUserEmail, 230 sendVerifyUserEmail,
183 isAbleToUploadVideo 231 isAbleToUploadVideo,
232 buildUser
184} 233}
185 234
186// --------------------------------------------------------------------------- 235// ---------------------------------------------------------------------------