49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
/**
|
|
* 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 { OG_SITE_NAME } from "../config.ts";
|
|
import { i18n } from "./i18n.ts";
|
|
import {
|
|
EmailKit,
|
|
escMd,
|
|
lookOf,
|
|
mdLink,
|
|
type RenderedEmail,
|
|
} from "./layout.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 markdown = [
|
|
`# ${escMd(i18n._("email.reset.title"))}`,
|
|
escMd(i18n._("email.reset.hi", { username })),
|
|
escMd(i18n._("email.reset.body", { site: OG_SITE_NAME, hours })),
|
|
mdLink(
|
|
i18n._("email.reset.button"),
|
|
resetUrl,
|
|
),
|
|
`*${escMd(i18n._("email.reset.fallback"))}*`,
|
|
"```\n" + resetUrl + "\n```",
|
|
`*${escMd(i18n._("email.reset.ignore"))}*`,
|
|
"---",
|
|
escMd(i18n._("email.reset.reason")),
|
|
].join("\n\n");
|
|
|
|
return new EmailKit(lookOf()).render({
|
|
subject: i18n._("email.reset.subject", { site: OG_SITE_NAME }),
|
|
preheader: i18n._("email.reset.preheader", { hours }),
|
|
markdown,
|
|
});
|
|
}
|