0.12.12 : add mail templates as single type
All checks were successful
Build release Docker image / Build Docker Images (push) Successful in 6m55s

This commit is contained in:
2025-12-02 23:06:50 +01:00
parent ddf2ced098
commit 460560bb89
10 changed files with 925 additions and 9 deletions

View File

@@ -46,6 +46,13 @@ module.exports = (plugin) => {
const sendConfirmationEmail = async (user) => {
// Génération du token de confirmation
const templates = await strapi
.documents("api::mails.mails")
.findFirst({ populate: "*" });
//const onCreateUser = templates.onCreateUser;
const onCreateUser = templates?.onCreateUser;
const confirmationToken = cryptoLib.randomBytes(20).toString("hex");
await edit(user.id, { confirmationToken });
@@ -54,7 +61,8 @@ module.exports = (plugin) => {
// Lecture du template HTML depuis le fichier
const htmlPath = path.join(process.cwd(), "public", "confirmation.html");
let html = await fs.readFile(htmlPath, "utf-8");
//let html = await fs.readFile(htmlPath, "utf-8");
let html = onCreateUser?.message;
// Remplacement des variables
html = html
@@ -63,12 +71,15 @@ module.exports = (plugin) => {
.replace(/{{YEAR}}/g, new Date().getFullYear().toString());
// Envoi de l'e-mail
await strapi.plugin("email").service("email").send({
to: user.email,
subject: "Confirme ton adresse e-mail",
html,
from: "ChoralSync <admin@harmonychoral.com>",
});
await strapi
.plugin("email")
.service("email")
.send({
to: user.email,
subject: onCreateUser?.subject ?? "Confirme ton adresse e-mail",
html,
from: "ChoralSync <admin@harmonychoral.com>",
});
return { ok: true };
};