0.12.12 : add mail templates as single type
All checks were successful
Build release Docker image / Build Docker Images (push) Successful in 6m55s
All checks were successful
Build release Docker image / Build Docker Images (push) Successful in 6m55s
This commit is contained in:
@@ -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 };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user