From a652654be76a49de237e5c35fd8d942c1bd98945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Thu, 24 Nov 2022 22:09:36 +0100 Subject: [PATCH] Refactor 'sendResetPasswordEmail' email to HTML and translatable --- backend/src/emails/accountActivation/html.pug | 2 +- backend/src/emails/resetPassword/html.pug | 20 +++++++++++++++++ backend/src/emails/resetPassword/subject.pug | 1 + backend/src/emails/sendEmailVariants.ts | 22 +++++++++++++++++++ backend/src/graphql/resolver/UserResolver.ts | 9 ++++---- backend/src/locales/de.json | 8 ++++++- backend/src/locales/en.json | 12 +++++++--- 7 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 backend/src/emails/resetPassword/html.pug create mode 100644 backend/src/emails/resetPassword/subject.pug diff --git a/backend/src/emails/accountActivation/html.pug b/backend/src/emails/accountActivation/html.pug index 9c631c960..f283e941e 100644 --- a/backend/src/emails/accountActivation/html.pug +++ b/backend/src/emails/accountActivation/html.pug @@ -11,7 +11,7 @@ html(lang=locale) br a(href=activationLink) #{activationLink} br - span= t('emails.accountActivation.orCopyLink') + span= t('emails.general.orCopyLink') p= t('emails.accountActivation.duration', { hours: timeDurationObject.hours, minutes: timeDurationObject.minutes }) br a(href=resendLink) #{resendLink} diff --git a/backend/src/emails/resetPassword/html.pug b/backend/src/emails/resetPassword/html.pug new file mode 100644 index 000000000..a3ced9a75 --- /dev/null +++ b/backend/src/emails/resetPassword/html.pug @@ -0,0 +1,20 @@ +doctype html +html(lang=locale) + head + title= t('emails.resetPassword.subject') + body + h1(style='margin-bottom: 24px;')= t('emails.resetPassword.subject') + #container.col + p(style='margin-bottom: 24px;')= t('emails.general.helloName', { firstName, lastName }) + p= t('emails.resetPassword.youOrSomeoneResetPassword') + p= t('emails.resetPassword.pleaseClickLink') + br + a(href=resetLink) #{resetLink} + br + span= t('emails.general.orCopyLink') + p= t('emails.resetPassword.duration', { hours: timeDurationObject.hours, minutes: timeDurationObject.minutes }) + br + a(href=resendLink) #{resendLink} + p(style='margin-top: 24px;')= t('emails.general.sincerelyYours') + br + span= t('emails.general.yourGradidoTeam') diff --git a/backend/src/emails/resetPassword/subject.pug b/backend/src/emails/resetPassword/subject.pug new file mode 100644 index 000000000..3d2b1f00f --- /dev/null +++ b/backend/src/emails/resetPassword/subject.pug @@ -0,0 +1 @@ += t('emails.resetPassword.subject') \ No newline at end of file diff --git a/backend/src/emails/sendEmailVariants.ts b/backend/src/emails/sendEmailVariants.ts index 1779cc297..e8f208eb0 100644 --- a/backend/src/emails/sendEmailVariants.ts +++ b/backend/src/emails/sendEmailVariants.ts @@ -124,3 +124,25 @@ export const sendContributionRejectedEmail = (data: { }, }) } + +export const sendResetPasswordEmail = (data: { + firstName: string + lastName: string + email: string + language: string + resetLink: string + timeDurationObject: Record +}): Promise | null> => { + return sendEmailTranslated({ + receiver: { to: `${data.firstName} ${data.lastName} <${data.email}>` }, + template: 'resetPassword', + locals: { + firstName: data.firstName, + lastName: data.lastName, + locale: data.language, + resetLink: data.resetLink, + timeDurationObject: data.timeDurationObject, + resendLink: CONFIG.EMAIL_LINK_FORGOTPASSWORD, + }, + }) +} diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 4ec4af166..6bdddb7b7 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -18,10 +18,10 @@ import UnsecureLoginArgs from '@arg/UnsecureLoginArgs' import UpdateUserInfosArgs from '@arg/UpdateUserInfosArgs' import { klicktippNewsletterStateMiddleware } from '@/middleware/klicktippMiddleware' import { OptInType } from '@enum/OptInType' -import { sendResetPasswordEmail as sendResetPasswordEmailMailer } from '@/mailer/sendResetPasswordEmail' import { sendAccountActivationEmail, sendAccountMultiRegistrationEmail, + sendResetPasswordEmail, } from '@/emails/sendEmailVariants' import { klicktippSignIn } from '@/apis/KlicktippController' import { RIGHTS } from '@/auth/RIGHTS' @@ -574,12 +574,13 @@ export class UserResolver { // optInCode = await checkOptInCode(optInCode, user, OptInType.EMAIL_OPT_IN_RESET_PASSWORD) logger.info(`optInCode for ${email}=${dbUserContact}`) // eslint-disable-next-line @typescript-eslint/no-unused-vars - const emailSent = await sendResetPasswordEmailMailer({ - link: activationLink(dbUserContact.emailVerificationCode), + const emailSent = await sendResetPasswordEmail({ firstName: user.firstName, lastName: user.lastName, email, - duration: printTimeDuration(CONFIG.EMAIL_CODE_VALID_TIME), + language: user.language, + resetLink: activationLink(dbUserContact.emailVerificationCode), + timeDurationObject: getTimeDurationObject(CONFIG.EMAIL_CODE_VALID_TIME), }) /* uncomment this, when you need the activation link on the console */ diff --git a/backend/src/locales/de.json b/backend/src/locales/de.json index 277728439..fd9b74662 100644 --- a/backend/src/locales/de.json +++ b/backend/src/locales/de.json @@ -9,7 +9,6 @@ "duration": "Der Link hat eine Gültigkeit von {hours} Stunden und {minutes} Minuten. Sollte die Gültigkeit des Links bereits abgelaufen sein, kannst du dir hier einen neuen Link schicken lassen, in dem du deine E-Mail-Adresse eingibst:", "emailRegistered": "deine E-Mail-Adresse wurde soeben bei Gradido registriert.", "pleaseClickLink": "Klicke bitte auf diesen Link, um die Registrierung abzuschließen und dein Gradido-Konto zu aktivieren:", - "orCopyLink": "oder kopiere den obigen Link in dein Browserfenster.", "subject": "Gradido: E-Mail Überprüfung" }, "accountMultiRegistration": { @@ -30,10 +29,17 @@ "subject": "Gradido: Dein Gemeinwohl-Beitrag wurde abgelehnt", "toSeeContributionsAndMessages": "Um deine Gemeinwohl-Beiträge und dazugehörige Nachrichten zu sehen, gehe in deinem Gradido-Konto ins Menü „Gemeinschaft“ auf den Tab „Meine Beiträge zum Gemeinwohl“!" }, + "resetPassword": { + "duration": "Der Link hat eine Gültigkeit von {hours} Stunden und {minutes} Minuten. Sollte die Gültigkeit des Links bereits abgelaufen sein, kannst du dir hier einen neuen Link schicken lassen, in dem du deine E-Mail-Adresse eingibst:", + "pleaseClickLink": "Wenn du es warst, klicke bitte auf den Link:", + "subject": "Gradido: Passwort zurücksetzen", + "youOrSomeoneResetPassword": "du, oder jemand anderes, hast für dieses Konto ein Zurücksetzen des Passworts angefordert." + }, "general": { "decimalSeparator": ",", "helloName": "Hallo {firstName} {lastName},", "linkToYourAccount": "Link zu deinem Konto:", + "orCopyLink": "oder kopiere den obigen Link in dein Browserfenster.", "pleaseDoNotReply": "Bitte antworte nicht auf diese E-Mail!", "sincerelyYours": "Liebe Grüße", "yourGradidoTeam": "dein Gradido-Team" diff --git a/backend/src/locales/en.json b/backend/src/locales/en.json index d4292b05f..c688102c6 100644 --- a/backend/src/locales/en.json +++ b/backend/src/locales/en.json @@ -9,7 +9,6 @@ "duration": "The link has a validity of {hours} hours and {minutes} minutes. If the validity of the link has already expired, you can have a new link sent to you here by entering your email address:", "emailRegistered": "Your email address has just been registered with Gradido.", "pleaseClickLink": "Please click on this link to complete the registration and activate your Gradido account:", - "orCopyLink": "or copy the link above into your browser window.", "subject": "Gradido: Email Verification" }, "accountMultiRegistration": { @@ -21,19 +20,26 @@ "subject": "Gradido: Try To Register Again With Your Email" }, "contributionConfirmed": { - "commonGoodContributionConfirmed": "your public good contribution “{contributionMemo}” has just been confirmed by {senderFirstName} {senderLastName} and credited to your Gradido account.", + "commonGoodContributionConfirmed": "Your public good contribution “{contributionMemo}” has just been confirmed by {senderFirstName} {senderLastName} and credited to your Gradido account.", "contributionAmount": "Amount: {contributionAmount} GDD", "subject": "Gradido: Your common good contribution was confirmed" }, "contributionRejected": { - "commonGoodContributionRejected": "your public good contribution “{contributionMemo}” was rejected by {senderFirstName} {senderLastName}.", + "commonGoodContributionRejected": "Your public good contribution “{contributionMemo}” was rejected by {senderFirstName} {senderLastName}.", "subject": "Gradido: Your common good contribution was rejected", "toSeeContributionsAndMessages": "To see your common good contributions and related messages, go to the “Community” menu in your Gradido account and click on the “My contributions to the common good” tab!" }, + "resetPassword": { + "duration": "The link has a validity of {hours} hours and {minutes} minutes. If the validity of the link has already expired, you can have a new link sent to you here by entering your email address:", + "pleaseClickLink": "If it was you, please click on the link:", + "subject": "Gradido: Reset password", + "youOrSomeoneResetPassword": "You, or someone else, requested a password reset for this account." + }, "general": { "decimalSeparator": ".", "helloName": "Hello {firstName} {lastName}", "linkToYourAccount": "Link to your account:", + "orCopyLink": "or copy the link above into your browser window.", "pleaseDoNotReply": "Please do not reply to this email!", "sincerelyYours": "Kind regards,", "yourGradidoTeam": "your Gradido team"