X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fusers%2Findex.ts;h=c1d72087cc3a5508fa0f300f9c80c38c6b7b2231;hb=3caf77d3b11f2dbc12e52d665183d36604c1dab9;hp=2e03587ce2e33e1e9d223b3286af0d98cb3c1d5d;hpb=a41b9da1a9ce49df82ea10c82de4c2fbc6d1b189;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index 2e03587ce..c1d72087c 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts @@ -6,7 +6,7 @@ import { getFormattedObjects } from '../../../helpers/utils' import { RATES_LIMIT, WEBSERVER } from '../../../initializers/constants' import { Emailer } from '../../../lib/emailer' import { Redis } from '../../../lib/redis' -import { createUserAccountAndChannelAndPlaylist } from '../../../lib/user' +import { createUserAccountAndChannelAndPlaylist, sendVerifyUserEmail } from '../../../lib/user' import { asyncMiddleware, asyncRetryTransactionMiddleware, @@ -50,11 +50,14 @@ import { UserRegister } from '../../../../shared/models/users/user-register.mode 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 @@ -144,7 +147,7 @@ usersRouter.post('/:id/reset-password', usersRouter.post('/ask-send-verify-email', askSendEmailLimiter, asyncMiddleware(usersAskSendVerifyEmailValidator), - asyncMiddleware(askSendVerifyUserEmail) + asyncMiddleware(reSendVerifyUserEmail) ) usersRouter.post('/:id/verify-email', @@ -181,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) @@ -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, body.channel) + 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) @@ -313,14 +320,7 @@ async function resetUserPassword (req: express.Request, res: express.Response) { return res.status(204).end() } -async function sendVerifyUserEmail (user: UserModel) { - const verificationString = await Redis.Instance.setVerifyEmailVerificationString(user.id) - const url = WEBSERVER.URL + '/verify-account/email?userId=' + user.id + '&verificationString=' + verificationString - await Emailer.Instance.addVerifyEmailJob(user.email, url) - return -} - -async function askSendVerifyUserEmail (req: express.Request, res: express.Response) { +async function reSendVerifyUserEmail (req: express.Request, res: express.Response) { const user = res.locals.user await sendVerifyUserEmail(user) @@ -332,6 +332,11 @@ async function verifyUserEmail (req: express.Request, res: express.Response) { const user = res.locals.user user.emailVerified = true + if (req.body.isPendingEmail === true) { + user.email = user.pendingEmail + user.pendingEmail = null + } + await user.save() return res.status(204).end()