diff options
Diffstat (limited to 'server/controllers/api/users/index.ts')
-rw-r--r-- | server/controllers/api/users/index.ts | 37 |
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' | |||
3 | import { tokensRouter } from '@server/controllers/api/users/token' | 3 | import { tokensRouter } from '@server/controllers/api/users/token' |
4 | import { Hooks } from '@server/lib/plugins/hooks' | 4 | import { Hooks } from '@server/lib/plugins/hooks' |
5 | import { OAuthTokenModel } from '@server/models/oauth/oauth-token' | 5 | import { OAuthTokenModel } from '@server/models/oauth/oauth-token' |
6 | import { MUser, MUserAccountDefault } from '@server/types/models' | 6 | import { MUserAccountDefault } from '@server/types/models' |
7 | import { HttpStatusCode, UserAdminFlag, UserCreate, UserCreateResult, UserRegister, UserRight, UserRole, UserUpdate } from '@shared/models' | 7 | import { pick } from '@shared/core-utils' |
8 | import { HttpStatusCode, UserCreate, UserCreateResult, UserRegister, UserRight, UserUpdate } from '@shared/models' | ||
8 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' | 9 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' |
9 | import { logger } from '../../../helpers/logger' | 10 | import { logger } from '../../../helpers/logger' |
10 | import { generateRandomString, getFormattedObjects } from '../../../helpers/utils' | 11 | import { generateRandomString, getFormattedObjects } from '../../../helpers/utils' |
@@ -14,7 +15,7 @@ import { sequelizeTypescript } from '../../../initializers/database' | |||
14 | import { Emailer } from '../../../lib/emailer' | 15 | import { Emailer } from '../../../lib/emailer' |
15 | import { Notifier } from '../../../lib/notifier' | 16 | import { Notifier } from '../../../lib/notifier' |
16 | import { Redis } from '../../../lib/redis' | 17 | import { Redis } from '../../../lib/redis' |
17 | import { createUserAccountAndChannelAndPlaylist, sendVerifyUserEmail } from '../../../lib/user' | 18 | import { buildUser, createUserAccountAndChannelAndPlaylist, sendVerifyUserEmail } from '../../../lib/user' |
18 | import { | 19 | import { |
19 | asyncMiddleware, | 20 | asyncMiddleware, |
20 | asyncRetryTransactionMiddleware, | 21 | asyncRetryTransactionMiddleware, |
@@ -175,18 +176,11 @@ export { | |||
175 | async function createUser (req: express.Request, res: express.Response) { | 176 | async 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) { | |||
225 | async function registerUser (req: express.Request, res: express.Response) { | 219 | async 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 | ||