import { CONFIG } from '../../../initializers/config'
import { sequelizeTypescript } from '../../../initializers/database'
import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
+import { UserRegister } from '../../../../shared/models/users/user-register.model'
const auditLogger = auditLoggerFactory('users')
-const loginRateLimiter = new RateLimit({
+// FIXME: https://github.com/nfriedly/express-rate-limit/issues/138
+// @ts-ignore
+const loginRateLimiter = RateLimit({
windowMs: RATES_LIMIT.LOGIN.WINDOW_MS,
max: RATES_LIMIT.LOGIN.MAX
})
+// @ts-ignore
const askSendEmailLimiter = new RateLimit({
windowMs: RATES_LIMIT.ASK_SEND_EMAIL.WINDOW_MS,
max: RATES_LIMIT.ASK_SEND_EMAIL.MAX
adminFlags: body.adminFlags || UserAdminFlag.NONE
})
- const { user, account } = await createUserAccountAndChannelAndPlaylist(userToCreate)
+ const { user, account } = await createUserAccountAndChannelAndPlaylist({ userToCreate: userToCreate })
auditLogger.create(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
logger.info('User %s with its channel and account created.', body.username)
user: {
id: user.id,
account: {
- id: account.id,
- uuid: account.Actor.uuid
+ id: account.id
}
}
}).end()
}
async function registerUser (req: express.Request, res: express.Response) {
- const body: UserCreate = req.body
+ const body: UserRegister = req.body
const userToCreate = new UserModel({
username: body.username,
emailVerified: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION ? false : null
})
- const { user } = await createUserAccountAndChannelAndPlaylist(userToCreate)
+ const { user } = 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)