aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/users/index.ts')
-rw-r--r--server/controllers/api/users/index.ts37
1 files changed, 12 insertions, 25 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index 7efc3a137..8a06bfe93 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -3,8 +3,9 @@ import RateLimit from 'express-rate-limit'
3import { tokensRouter } from '@server/controllers/api/users/token' 3import { tokensRouter } from '@server/controllers/api/users/token'
4import { Hooks } from '@server/lib/plugins/hooks' 4import { Hooks } from '@server/lib/plugins/hooks'
5import { OAuthTokenModel } from '@server/models/oauth/oauth-token' 5import { OAuthTokenModel } from '@server/models/oauth/oauth-token'
6import { MUser, MUserAccountDefault } from '@server/types/models' 6import { MUserAccountDefault } from '@server/types/models'
7import { HttpStatusCode, UserAdminFlag, UserCreate, UserCreateResult, UserRegister, UserRight, UserRole, UserUpdate } from '@shared/models' 7import { pick } from '@shared/core-utils'
8import { HttpStatusCode, UserCreate, UserCreateResult, UserRegister, UserRight, UserUpdate } from '@shared/models'
8import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' 9import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger'
9import { logger } from '../../../helpers/logger' 10import { logger } from '../../../helpers/logger'
10import { generateRandomString, getFormattedObjects } from '../../../helpers/utils' 11import { generateRandomString, getFormattedObjects } from '../../../helpers/utils'
@@ -14,7 +15,7 @@ import { sequelizeTypescript } from '../../../initializers/database'
14import { Emailer } from '../../../lib/emailer' 15import { Emailer } from '../../../lib/emailer'
15import { Notifier } from '../../../lib/notifier' 16import { Notifier } from '../../../lib/notifier'
16import { Redis } from '../../../lib/redis' 17import { Redis } from '../../../lib/redis'
17import { createUserAccountAndChannelAndPlaylist, sendVerifyUserEmail } from '../../../lib/user' 18import { buildUser, createUserAccountAndChannelAndPlaylist, sendVerifyUserEmail } from '../../../lib/user'
18import { 19import {
19 asyncMiddleware, 20 asyncMiddleware,
20 asyncRetryTransactionMiddleware, 21 asyncRetryTransactionMiddleware,
@@ -175,18 +176,11 @@ export {
175async function createUser (req: express.Request, res: express.Response) { 176async function createUser (req: express.Request, res: express.Response) {
176 const body: UserCreate = req.body 177 const body: UserCreate = req.body
177 178
178 const userToCreate = new UserModel({ 179 const userToCreate = buildUser({
179 username: body.username, 180 ...pick(body, [ 'username', 'password', 'email', 'role', 'videoQuota', 'videoQuotaDaily', 'adminFlags' ]),
180 password: body.password, 181
181 email: body.email, 182 emailVerified: null
182 nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, 183 })
183 p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED,
184 autoPlayVideo: true,
185 role: body.role,
186 videoQuota: body.videoQuota,
187 videoQuotaDaily: body.videoQuotaDaily,
188 adminFlags: body.adminFlags || UserAdminFlag.NONE
189 }) as MUser
190 184
191 // NB: due to the validator usersAddValidator, password==='' can only be true if we can send the mail. 185 // NB: due to the validator usersAddValidator, password==='' can only be true if we can send the mail.
192 const createPassword = userToCreate.password === '' 186 const createPassword = userToCreate.password === ''
@@ -225,16 +219,9 @@ async function createUser (req: express.Request, res: express.Response) {
225async function registerUser (req: express.Request, res: express.Response) { 219async function registerUser (req: express.Request, res: express.Response) {
226 const body: UserRegister = req.body 220 const body: UserRegister = req.body
227 221
228 const userToCreate = new UserModel({ 222 const userToCreate = buildUser({
229 username: body.username, 223 ...pick(body, [ 'username', 'password', 'email' ]),
230 password: body.password, 224
231 email: body.email,
232 nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
233 p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED,
234 autoPlayVideo: true,
235 role: UserRole.USER,
236 videoQuota: CONFIG.USER.VIDEO_QUOTA,
237 videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY,
238 emailVerified: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION ? false : null 225 emailVerified: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION ? false : null
239 }) 226 })
240 227