From 8da7c55deb5c0b4fccb7f18688613d06dd92df45 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 5 Mar 2021 18:29:22 +0100 Subject: [PATCH] Added new mailer function ref #5 --- src/Mailer.ts | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Mailer.ts b/src/Mailer.ts index d2752f8..bf844f1 100644 --- a/src/Mailer.ts +++ b/src/Mailer.ts @@ -121,8 +121,8 @@ export class Mailer { /** * Function for sending a reset mail from the reset mail template. - * @param to_address The address the mail will be sent to. Should always get pulled from a user object. - * @param token The requested password reset token - will be combined with the app_url to generate a password reset link. + * @param to_address The address the mail will be sent to. Should always get pulled from a runner object. + * @param token The runner's selfservice token - will be combined with the app_url to generate a selfservice profile link. */ public async sendWelcomeMail(to_address: string, token: string, locale: string = "en") { await i18next.changeLanguage(locale); @@ -152,6 +152,39 @@ export class Mailer { await this.sendMail(mail); } + /** + * Function for sending a selfservice link forgotten mail from the runner_forgot template. + * @param to_address The address the mail will be sent to. Should always get pulled from a runner object. + * @param token The runner's selfservice token - will be combined with the app_url to generate a selfservice profile link. + */ + public async sendSelfserviceForgottenMail(to_address: string, token: string, locale: string = "en") { + await i18next.changeLanguage(locale); + + const replacements = { + recipient_mail: to_address, + copyright_owner: config.copyright_owner, + link_imprint: `${config.app_url}/imprint`, + link_privacy: `${config.app_url}/privacy`, + selfservice_link: `${config.app_url}/selfservice/profile/${token}`, + forgot_link: `${config.app_url}/selfservice`, + contact_mail: config.contact_mail, + event_name: config.event_name + } + + const template_html = Handlebars.compile(fs.readFileSync(__dirname + '/templates/runner_forgot.html', { encoding: 'utf8' })); + const template_txt = Handlebars.compile(fs.readFileSync(__dirname + '/templates/runner_forgot.txt', { encoding: 'utf8' })); + const body_html = template_html(replacements); + const body_txt = template_txt(replacements); + + const mail: MailOptions = { + to: to_address, + subject: i18next.t("your-event_name-profile", Mailer.interpolations).toString(), + text: body_txt, + html: body_html + }; + await this.sendMail(mail); + } + /** * Wrapper function for sending a mail via this object's transporter. * @param mail MailOptions object containing the