- const userToCreate = new UserModel({
- username: body.username,
- password: body.password,
- email: body.email,
- nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
- autoPlayVideo: true,
- role: body.role,
- videoQuota: body.videoQuota,
- videoQuotaDaily: body.videoQuotaDaily,
- adminFlags: body.adminFlags || UserAdminFlag.NONE
- }) as MUser
-
- const { user, account } = await createUserAccountAndChannelAndPlaylist({ userToCreate: userToCreate })
+
+ const userToCreate = buildUser({
+ ...pick(body, [ 'username', 'password', 'email', 'role', 'videoQuota', 'videoQuotaDaily', 'adminFlags' ]),
+
+ emailVerified: null
+ })
+
+ // NB: due to the validator usersAddValidator, password==='' can only be true if we can send the mail.
+ const createPassword = userToCreate.password === ''
+ if (createPassword) {
+ userToCreate.password = await generateRandomString(20)
+ }
+
+ const { user, account, videoChannel } = await createUserAccountAndChannelAndPlaylist({
+ userToCreate,
+ channelNames: body.channelName && { name: body.channelName, displayName: body.channelName }
+ })