/** * Renders the email carrying a password reset link. `requestPasswordReset` * (`password-reset-service.ts`) sends it, in the instance's style and * language: whoever asks isn't signed in, so their own settings don't apply. * * @module */ import { DEFAULT_STYLE, EMAIL_LOCALE, OG_SITE_NAME } from "../config.ts"; import { EmailKit, esc, type RenderedEmail } from "./layout.ts"; import { STRINGS } from "./strings.ts"; /** * Returns the reset email of `username`, whose button opens `resetUrl`. The * link stays usable for `hours`, which the email states. */ export function renderPasswordResetEmail( username: string, resetUrl: string, hours: number, ): RenderedEmail { const t = STRINGS[EMAIL_LOCALE].reset; const kit = new EmailKit( { style: DEFAULT_STYLE, scheme: "auto" }, EMAIL_LOCALE, ); const subject = t.subject(OG_SITE_NAME); const urlBox = `${esc(resetUrl)}`; const body = kit.para(esc(t.hi(username))) + kit.para(esc(t.body(OG_SITE_NAME, hours))) + kit.button(esc(t.button), resetUrl) + kit.note(esc(t.fallback), "margin-bottom:8px;") + urlBox + kit.note(esc(t.ignore)); return { subject, html: kit.document({ subject, preheader: t.preheader(hours), title: esc(t.title), body, footer: kit.footer(esc(t.reason)), }), text: [ t.title, "", t.hi(username), "", t.body(OG_SITE_NAME, hours), "", resetUrl, "", t.ignore, "", "--", t.reason, ].join("\n"), }; }