From 963023abe6acf31799f6474d78489c8013f664fa Mon Sep 17 00:00:00 2001 From: kimsible Date: Mon, 20 Jul 2020 14:58:58 +0200 Subject: Fix: display username in password-reset and verify-email notifs --- server/controllers/api/users/index.ts | 2 +- server/lib/emailer.ts | 6 ++++-- server/lib/emails/password-reset/html.pug | 6 +++--- server/lib/user.ts | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index fcd828ae3..5939f6125 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts @@ -340,7 +340,7 @@ async function askResetUserPassword (req: express.Request, res: express.Response const verificationString = await Redis.Instance.setResetPasswordVerificationString(user.id) const url = WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString - await Emailer.Instance.addPasswordResetEmailJob(user.email, url) + await Emailer.Instance.addPasswordResetEmailJob(user.username, user.email, url) return res.status(204).end() } diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index c08732b48..ee8498c41 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts @@ -387,12 +387,13 @@ class Emailer { return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) } - addPasswordResetEmailJob (to: string, resetPasswordUrl: string) { + addPasswordResetEmailJob (username: string, to: string, resetPasswordUrl: string) { const emailPayload: EmailPayload = { template: 'password-reset', to: [ to ], subject: 'Reset your account password', locals: { + username, resetPasswordUrl } } @@ -414,12 +415,13 @@ class Emailer { return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) } - addVerifyEmailJob (to: string, verifyEmailUrl: string) { + addVerifyEmailJob (username: string, to: string, verifyEmailUrl: string) { const emailPayload: EmailPayload = { template: 'verify-email', to: [ to ], subject: `Verify your email on ${WEBSERVER.HOST}`, locals: { + username, verifyEmailUrl } } diff --git a/server/lib/emails/password-reset/html.pug b/server/lib/emails/password-reset/html.pug index bb6a9d16b..ac33db5d7 100644 --- a/server/lib/emails/password-reset/html.pug +++ b/server/lib/emails/password-reset/html.pug @@ -5,8 +5,8 @@ block title block content p. - A reset password procedure for your account ${to} has been requested on #[a(href=WEBSERVER.URL) #{WEBSERVER.HOST}]. - Please follow #[a(href=resetPasswordUrl) this link] to reset it: #[a(href=resetPasswordUrl) #{resetPasswordUrl}] + A reset password procedure for your account #{username} has been requested on #[a(href=WEBSERVER.URL) #{WEBSERVER.HOST}]. + Please follow #[a(href=resetPasswordUrl) this link] to reset it: #[a(href=resetPasswordUrl) #{resetPasswordUrl}] (the link will expire within 1 hour) p. - If you are not the person who initiated this request, please ignore this email. \ No newline at end of file + If you are not the person who initiated this request, please ignore this email. diff --git a/server/lib/user.ts b/server/lib/user.ts index 43eef8ab1..dabb35061 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts @@ -111,8 +111,9 @@ async function sendVerifyUserEmail (user: MUser, isPendingEmail = false) { if (isPendingEmail) url += '&isPendingEmail=true' const email = isPendingEmail ? user.pendingEmail : user.email + const username = user.username - await Emailer.Instance.addVerifyEmailJob(email, url) + await Emailer.Instance.addVerifyEmailJob(username, email, url) } // --------------------------------------------------------------------------- -- cgit v1.2.3