-async function registerUser (req: express.Request, res: express.Response) {
- const body: UserRegister = req.body
-
- const userToCreate = new UserModel({
- username: body.username,
- password: body.password,
- email: body.email,
- nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
- p2pEnabled: CONFIG.DEFAULTS.P2P.ENABLED,
- autoPlayVideo: true,
- role: UserRole.USER,
- videoQuota: CONFIG.USER.VIDEO_QUOTA,
- videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY,
- emailVerified: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION ? false : null
- })
-
- const { user, account, videoChannel } = await createUserAccountAndChannelAndPlaylist({
- userToCreate: userToCreate,
- userDisplayName: body.displayName || undefined,
- channelNames: body.channel
- })
-
- auditLogger.create(body.username, new UserAuditView(user.toFormattedJSON()))
- logger.info('User %s with its channel and account registered.', body.username)
-
- if (CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) {
- await sendVerifyUserEmail(user)
- }
-
- Notifier.Instance.notifyOnNewUserRegistration(user)
-
- Hooks.runAction('action:api.user.registered', { body, user, account, videoChannel, req, res })
-
- return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
-}
-