feat(auth): #127 forgot-password + reset-password API (BDD + mail)
Made-with: Cursor
This commit is contained in:
@@ -238,4 +238,31 @@ export class MailService {
|
||||
|
||||
await this.sendEmail(to, subject, html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ticket #127 — lien application `/reset-password?token=` (pas create-password).
|
||||
*/
|
||||
async sendPasswordResetEmail(recipient: {
|
||||
email: string;
|
||||
prenom: string;
|
||||
nom: string;
|
||||
token: string;
|
||||
}): Promise<void> {
|
||||
const appName = this.configService.get<string>('app_name', "P'titsPas");
|
||||
const appUrl = (this.configService.get<string>('app_url', 'https://app.ptits-pas.fr') || '').replace(/\/+$/, '');
|
||||
const resetPasswordUrl = `${appUrl}/reset-password?token=${encodeURIComponent(recipient.token)}`;
|
||||
|
||||
const filePath = join(__dirname, 'templates', 'password-reset.hbs');
|
||||
const source = readFileSync(filePath, 'utf8');
|
||||
const compiled = Handlebars.compile(source);
|
||||
const html = compiled({
|
||||
prenom: recipient.prenom || '',
|
||||
nom: recipient.nom || '',
|
||||
appName,
|
||||
resetPasswordUrl,
|
||||
}) as string;
|
||||
|
||||
const subject = `${appName} — Réinitialisation de votre mot de passe`;
|
||||
await this.sendEmail(recipient.email, subject, html);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user