68 lines
1.8 KiB
TypeScript
68 lines
1.8 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 { 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 = `<div${
|
|
kit.paint(
|
|
{ fg: "sec", bg: "soft" },
|
|
`font-family:Menlo,Consolas,'Courier New',monospace;font-size:12px;line-height:1.5;border-radius:${
|
|
Math.min(kit.style.radius.img, 6)
|
|
}px;padding:10px 12px;margin:0 0 22px;word-break:break-all;`,
|
|
)
|
|
}>${esc(resetUrl)}</div>`;
|
|
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"),
|
|
};
|
|
}
|