32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { EmailTemplates, Errors } from "sealious";
|
|
import type TheApp from "../app.js";
|
|
|
|
export default async function PasswordResetTemplate(
|
|
app: TheApp,
|
|
{ email_address, token }: { email_address: string; token: string }
|
|
) {
|
|
const matching_users = await app.collections["users"]
|
|
.suList()
|
|
.filter({ email: email_address })
|
|
.fetch();
|
|
|
|
if (!matching_users.items.length) {
|
|
throw new Errors.NotFound("No user with that email");
|
|
}
|
|
|
|
const username = matching_users.items[0]?.get("username");
|
|
|
|
const context = new app.Context();
|
|
return EmailTemplates.Simple(app, {
|
|
subject: context.i18n`[${app.manifest.name}] Password reset request`,
|
|
to: `${String(username)}<${email_address}>`,
|
|
text: `Hello, ${username}. Someone requested a password reset on your account on ${app.manifest.name}. If it was you, use the link below to change the password. Otherwise, ignore this message.`,
|
|
buttons: [
|
|
{
|
|
text: context.i18n`Change password`,
|
|
href: `${app.manifest.base_url}/confirm-password-reset?token=${token}&email=${email_address}`,
|
|
},
|
|
],
|
|
});
|
|
}
|