0.12.9 : fix send email validation
All checks were successful
Build release Docker image / Build Docker Images (push) Successful in 12m51s
All checks were successful
Build release Docker image / Build Docker Images (push) Successful in 12m51s
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "harmony-back",
|
"name": "harmony-back",
|
||||||
"version": "0.12.8",
|
"version": "0.12.9",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "A Strapi application",
|
"description": "A Strapi application",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
166
src/email-templates/confirmation.html
Normal file
166
src/email-templates/confirmation.html
Normal 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, "Segoe UI", Roboto,
|
||||||
|
"Helvetica Neue", 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 qu’une é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 n’es pas à l’origine 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 d’aide ? Réponds directement à cet e-mail ou consulte notre
|
||||||
|
<a href="https://www.choralsync.com/help" style="color: #0369a1"
|
||||||
|
>centre d’aide</a
|
||||||
|
>.
|
||||||
|
</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"name": "Apache 2.0",
|
"name": "Apache 2.0",
|
||||||
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
|
"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": {
|
"x-strapi-config": {
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
|||||||
@@ -1,7 +1,75 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const lod = require("lodash");
|
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) => {
|
module.exports = (plugin) => {
|
||||||
const rawProviders = plugin.services.providers({ strapi });
|
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) => {
|
const getService = (name) => {
|
||||||
return strapi.plugin("users-permissions").service(name);
|
return strapi.plugin("users-permissions").service(name);
|
||||||
@@ -47,9 +115,13 @@ module.exports = (plugin) => {
|
|||||||
where: { email },
|
where: { email },
|
||||||
});
|
});
|
||||||
|
|
||||||
const advancedSettings = await strapi
|
const advancedSettings = (await strapi
|
||||||
.store({ type: "plugin", name: "users-permissions", key: "advanced" })
|
.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 });
|
let user = lod.find(users, { provider });
|
||||||
if (lod.isEmpty(user)) {
|
if (lod.isEmpty(user)) {
|
||||||
@@ -453,6 +525,8 @@ module.exports = (plugin) => {
|
|||||||
activityType: "user" as const,
|
activityType: "user" as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
await sendConfirmationEmail(result);
|
||||||
|
|
||||||
await strapi.entityService.update(
|
await strapi.entityService.update(
|
||||||
"plugin::users-permissions.user",
|
"plugin::users-permissions.user",
|
||||||
result.id,
|
result.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user