]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/users/index.ts
Improve registration
[github/Chocobozzz/PeerTube.git] / server / controllers / api / users / index.ts
index 0aafba66e6f0f3f6f9fac87e28f4bb1ea5b6d32e..99f51a64831200228d601ebe082098ffda1418e8 100644 (file)
@@ -46,14 +46,18 @@ import { mySubscriptionsRouter } from './my-subscriptions'
 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
@@ -180,7 +184,7 @@ async function createUser (req: express.Request, res: express.Response) {
     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)
@@ -189,15 +193,14 @@ async function createUser (req: express.Request, res: express.Response) {
     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,
@@ -211,7 +214,11 @@ async function registerUser (req: express.Request, res: express.Response) {
     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)