0.12.9 : fix send email validation
All checks were successful
Build release Docker image / Build Docker Images (push) Successful in 12m51s

This commit is contained in:
2025-11-30 20:51:56 +01:00
parent a928acb7d2
commit 7df45f5c1c
4 changed files with 244 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "harmony-back",
"version": "0.12.8",
"version": "0.12.9",
"private": true,
"description": "A Strapi application",
"scripts": {

View File

@@ -0,0 +1,166 @@
<!-- Pré-en-tête (préheader) : aperçu dans certaines boîtes mail -->
<span style="display: none; max-height: 0; overflow: hidden"
>Confirme ton adresse e-mail en un clic pour activer ton compte.</span
>
<table
role="presentation"
width="100%"
cellpadding="0"
cellspacing="0"
style="
background-color: #f5f7fa;
padding: 24px 0;
font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto,
&quot;Helvetica Neue&quot;, Arial;
"
>
<tr>
<td align="center">
<table
role="presentation"
width="600"
cellpadding="0"
cellspacing="0"
style="
background-color: #ffffff;
border-radius: 12px;
overflow: hidden;
box-shadow: 0 6px 18px rgba(20, 30, 50, 0.08);
"
>
<!-- En-tête -->
<tr>
<td style="padding: 28px 32px 8px">
<div style="display: flex; align-items: center; gap: 12px">
<img
src="https://www.choralsync.com/logo_mini.png"
alt="Votre application"
width="48"
height="48"
style="display: block; border-radius: 8px; border: 0"
/>
<div>
<h1 style="margin: 0; font-size: 18px; color: #0f1724">
ChoralSync
</h1>
<p style="margin: 2px 0 0; font-size: 12px; color: #6b7280">
Bienvenue — plus quune étape
</p>
</div>
</div>
</td>
</tr>
<!-- Corps -->
<tr>
<td style="padding: 20px 32px 8px; color: #0f1724">
<h2 style="margin: 0 0 8px; font-size: 20px">
Bonjour {{USER_NAME}},
</h2>
<p
style="
margin: 0 0 16px;
font-size: 15px;
line-height: 1.5;
color: #374151;
"
>
Merci de têtre inscrit. Clique sur le bouton ci-dessous pour
confirmer ton adresse e-mail et activer ton compte.
</p>
<!-- Bouton -->
<table
role="presentation"
cellpadding="0"
cellspacing="0"
style="margin: 20px 0"
>
<tr>
<td align="center">
<a
href="{{CONFIRM_URL}}"
style="
display: inline-block;
padding: 12px 22px;
border-radius: 10px;
text-decoration: none;
font-weight: 600;
font-size: 15px;
background-image: linear-gradient(
90deg,
#6366f1,
#06b6d4
);
color: #ffffff;
"
>
Confirmer mon e-mail
</a>
</td>
</tr>
</table>
<!-- Lien de secours -->
<p style="margin: 8px 0 0; font-size: 13px; color: #6b7280">
Si le bouton ne fonctionne pas, copie-colle ce lien dans ton
navigateur :
</p>
<p
style="
word-break: break-all;
font-size: 12px;
color: #0f1724;
margin: 8px 0 0;
padding: 10px;
background: #f3f4f6;
border-radius: 8px;
border: 1px solid #e6e9ef;
"
>
<a
href="{{CONFIRM_URL}}"
style="color: #0369a1; text-decoration: underline"
>{{CONFIRM_URL}}</a
>
</p>
</td>
</tr>
<!-- Pied de mail -->
<tr>
<td
style="
padding: 18px 32px 28px;
color: #9ca3af;
font-size: 13px;
border-top: 1px solid #f1f3f6;
"
>
<p style="margin: 0 0 6px">
Si tu nes pas à lorigine de cette inscription, ignore cet
e-mail.
</p>
<p style="margin: 0; font-size: 12px; color: #9ca3af">
© ChoralSync {{YEAR}} •
<a
href="https://www.choralsync.com"
style="color: #9ca3af; text-decoration: underline"
>www.choralsync.com</a
>
</p>
</td>
</tr>
</table>
<div style="height: 14px"></div>
<p style="font-size: 12px; color: #9ca3af; margin: 0">
Besoin daide ? Réponds directement à cet e-mail ou consulte notre
<a href="https://www.choralsync.com/help" style="color: #0369a1"
>centre daide</a
>.
</p>
</td>
</tr>
</table>

View File

@@ -14,7 +14,7 @@
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"x-generation-date": "2025-11-21T12:49:29.594Z"
"x-generation-date": "2025-11-30T19:50:21.758Z"
},
"x-strapi-config": {
"plugins": [

View File

@@ -1,7 +1,75 @@
"use strict";
const lod = require("lodash");
const utils = require("@strapi/utils");
const { concat, compact, isArray, toNumber, getOr } = require("lodash/fp");
const cryptoLib = require("crypto");
const bcrypt = require("bcryptjs");
module.exports = (plugin) => {
const rawProviders = plugin.services.providers({ strapi });
const { ApplicationError, ValidationError, ForbiddenError } = utils.errors;
const USER_MODEL_UID = "plugin::users-permissions.user";
const sanitizeUser = (user, ctx) => {
const { auth } = ctx.state;
const userSchema = strapi.getModel("plugin::users-permissions.user");
return strapi.contentAPI.sanitize.output(user, userSchema, { auth });
};
const ensureHashedPasswords = async (values) => {
const attributes = strapi.getModel(USER_MODEL_UID).attributes;
for (const key in values) {
if (attributes[key] && attributes[key].type === "password") {
// Check if a custom encryption.rounds has been set on the password attribute
const rounds = toNumber(
getOr(10, "encryption.rounds", attributes[key])
);
values[key] = await bcrypt.hash(values[key], rounds);
}
}
values["confirmed"] = false;
return values;
};
const edit = async (userId, params = {}) => {
return strapi.db.query(USER_MODEL_UID).update({
where: { id: userId },
data: await ensureHashedPasswords(params),
populate: ["role"],
});
};
const sendConfirmationEmail = async (user) => {
// Génération du token de confirmation
const confirmationToken = cryptoLib.randomBytes(20).toString("hex");
await edit(user.id, { confirmationToken });
const confirmUrl = `${process.env.NEXTJS_URL}/confirmation/submit?confirmation=${confirmationToken}`;
// Récupération du template HTML défini dans plugins.ts
let html = strapi
.plugin("email")
.config("settings.templates.confirmation.html") as string;
// Remplacement des variables
html = html
.replace(/{{USER_NAME}}/g, user.username || user.email)
.replace(/{{CONFIRM_URL}}/g, confirmUrl)
.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>",
});
return { ok: true };
};
const getService = (name) => {
return strapi.plugin("users-permissions").service(name);
@@ -47,9 +115,13 @@ module.exports = (plugin) => {
where: { email },
});
const advancedSettings = await strapi
const advancedSettings = (await strapi
.store({ type: "plugin", name: "users-permissions", key: "advanced" })
.get();
.get()) as {
allow_register: boolean;
unique_email?: boolean;
default_role?: string;
};
let user = lod.find(users, { provider });
if (lod.isEmpty(user)) {
@@ -453,6 +525,8 @@ module.exports = (plugin) => {
activityType: "user" as const,
};
await sendConfirmationEmail(result);
await strapi.entityService.update(
"plugin::users-permissions.user",
result.id,