Compare commits
5 Commits
1a3ea9e0c1
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 0648bf74bd | |||
| d469fc41e8 | |||
| 5af0f28b39 | |||
| fd14d20dd0 | |||
| 7d020c33b6 |
@@ -3,16 +3,18 @@ export default () => ({
|
|||||||
config: {
|
config: {
|
||||||
provider: "nodemailer",
|
provider: "nodemailer",
|
||||||
providerOptions: {
|
providerOptions: {
|
||||||
host: "mail.harmonychoral.com",
|
host: "smtp.zeptomail.eu",
|
||||||
port: 465,
|
port: 587,
|
||||||
auth: {
|
auth: {
|
||||||
user: "admin@harmonychoral.com",
|
user: "emailapikey",
|
||||||
pass: "Apslxnap12bn23",
|
pass: "yA6KbHsJ4lrywWtTFUc+0pSC94lm/aE/2nzks3i2fpZ1LYXp3qE71RBvd4O4c2CLjdfT5a9UbIkVJoCwvIpbfpczPIBXJpTGTuv4P2uV48xh8ciEYNYjhJivALIWFqVOeBsnDyo4QfEjWA==",
|
||||||
},
|
},
|
||||||
|
debug: true,
|
||||||
|
logger: true,
|
||||||
},
|
},
|
||||||
settings: {
|
settings: {
|
||||||
defaultFrom: "admin@harmonychoral.com",
|
defaultFrom: "ChoralSync <noreply@choralsync.com>",
|
||||||
defaultReplyTo: "admin@harmonychoral.com",
|
defaultReplyTo: "contact@choralsync.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "harmony-back",
|
"name": "harmony-back",
|
||||||
"version": "0.13.7",
|
"version": "0.13.9",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "A Strapi application",
|
"description": "A Strapi application",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -67,16 +67,6 @@
|
|||||||
"videos",
|
"videos",
|
||||||
"audios"
|
"audios"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"logo": {
|
|
||||||
"allowedTypes": [
|
|
||||||
"images",
|
|
||||||
"files",
|
|
||||||
"videos",
|
|
||||||
"audios"
|
|
||||||
],
|
|
||||||
"type": "media",
|
|
||||||
"multiple": false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,14 @@
|
|||||||
"pending_admin_approval",
|
"pending_admin_approval",
|
||||||
"decline"
|
"decline"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"invite_email": {
|
||||||
|
"type": "email",
|
||||||
|
"private": true
|
||||||
|
},
|
||||||
|
"invite_token": {
|
||||||
|
"type": "string",
|
||||||
|
"private": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,97 @@
|
|||||||
/**
|
import { factories } from "@strapi/strapi";
|
||||||
* choral-membership controller
|
import crypto from "crypto";
|
||||||
*/
|
|
||||||
|
|
||||||
import { factories } from '@strapi/strapi'
|
export default factories.createCoreController(
|
||||||
|
"api::choral-membership.choral-membership",
|
||||||
|
({ strapi }) => ({
|
||||||
|
async create(ctx) {
|
||||||
|
const { data } = ctx.request.body;
|
||||||
|
const inviter = ctx.state.user;
|
||||||
|
|
||||||
export default factories.createCoreController('api::choral-membership.choral-membership');
|
// 1. Déterminer le type d'invitation
|
||||||
|
const isExternalInvite = !!data.invite_email && !data.user;
|
||||||
|
const isInternalInvite = !!data.user;
|
||||||
|
|
||||||
|
let token = null;
|
||||||
|
let targetEmail = null;
|
||||||
|
|
||||||
|
// 2. Configuration commune
|
||||||
|
// On force le statut "en attente" peut importe le type d'invité
|
||||||
|
ctx.request.body.data.state = "pending_user_approval";
|
||||||
|
if (!data.role) {
|
||||||
|
ctx.request.body.data.role = "member";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Traitement spécifique selon le cas
|
||||||
|
if (isExternalInvite) {
|
||||||
|
// Cas A : Utilisateur externe (Token requis)
|
||||||
|
token = crypto.randomBytes(32).toString("hex");
|
||||||
|
ctx.request.body.data.invite_token = token;
|
||||||
|
ctx.request.body.data.invite_email = data.invite_email.toLowerCase();
|
||||||
|
targetEmail = data.invite_email.toLowerCase();
|
||||||
|
} else if (isInternalInvite) {
|
||||||
|
// Cas B : Utilisateur existant (Pas de token)
|
||||||
|
// On s'assure de nettoyer les champs d'invitation externe au cas où le front les enverrait par erreur
|
||||||
|
ctx.request.body.data.invite_token = null;
|
||||||
|
ctx.request.body.data.invite_email = null;
|
||||||
|
|
||||||
|
// On récupère l'email de l'utilisateur existant pour lui envoyer une notification
|
||||||
|
const invitedUser = await strapi
|
||||||
|
.documents("plugin::users-permissions.user")
|
||||||
|
.findMany({
|
||||||
|
filters: {
|
||||||
|
id: data.user,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (invitedUser && invitedUser.length > 0) {
|
||||||
|
targetEmail = invitedUser[0].email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Exécution de la création native par Strapi
|
||||||
|
const response = await super.create(ctx);
|
||||||
|
|
||||||
|
// 5. Post-traitement : Envoi de l'email
|
||||||
|
if (response && targetEmail) {
|
||||||
|
try {
|
||||||
|
const chorals = await strapi
|
||||||
|
.documents("api::choral.choral")
|
||||||
|
.findMany({
|
||||||
|
filters: {
|
||||||
|
id: data.choral,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const choral = chorals[0];
|
||||||
|
|
||||||
|
if (isExternalInvite) {
|
||||||
|
// Email d'invitation avec le lien tokenisé
|
||||||
|
await strapi
|
||||||
|
.service("api::mails.mails")
|
||||||
|
.sendInvitation(
|
||||||
|
targetEmail,
|
||||||
|
inviter?.username || "Un membre",
|
||||||
|
choral?.name || "votre chorale",
|
||||||
|
token,
|
||||||
|
);
|
||||||
|
} else if (isInternalInvite) {
|
||||||
|
// Email de notification pour un utilisateur existant
|
||||||
|
// Ici le token est 'null', on prévient le service que c'est un user interne
|
||||||
|
await strapi.service("api::mails.mails").sendInvitation(
|
||||||
|
targetEmail,
|
||||||
|
inviter?.username || "Un membre",
|
||||||
|
choral?.name || "votre chorale",
|
||||||
|
null, // On passe explicitement null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
"Erreur lors de l'envoi de l'email d'invitation :",
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|||||||
@@ -115,6 +115,16 @@
|
|||||||
},
|
},
|
||||||
"available_roles": {
|
"available_roles": {
|
||||||
"type": "json"
|
"type": "json"
|
||||||
|
},
|
||||||
|
"logo": {
|
||||||
|
"allowedTypes": [
|
||||||
|
"images",
|
||||||
|
"files",
|
||||||
|
"videos",
|
||||||
|
"audios"
|
||||||
|
],
|
||||||
|
"type": "media",
|
||||||
|
"multiple": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,5 +33,5 @@ export default factories.createCoreController(
|
|||||||
const result = await super.create(ctx);
|
const result = await super.create(ctx);
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -25,6 +25,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"component": "mail.mail"
|
"component": "mail.mail"
|
||||||
|
},
|
||||||
|
"onInviteUser": {
|
||||||
|
"type": "component",
|
||||||
|
"repeatable": true,
|
||||||
|
"pluginOptions": {
|
||||||
|
"i18n": {
|
||||||
|
"localized": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"component": "mail.mail"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,61 @@
|
|||||||
/**
|
import { factories } from "@strapi/strapi";
|
||||||
* mails service
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { factories } from '@strapi/strapi';
|
export default factories.createCoreService(
|
||||||
|
"api::mails.mails",
|
||||||
|
({ strapi }) => ({
|
||||||
|
// Notre méthode personnalisée
|
||||||
|
async sendInvitation(
|
||||||
|
emailAddress: string,
|
||||||
|
inviterName: string,
|
||||||
|
choirName: string,
|
||||||
|
inviteToken: string | null,
|
||||||
|
) {
|
||||||
|
// 1. Définir le lien de redirection selon le type d'utilisateur
|
||||||
|
// S'il y a un token, c'est un nouvel utilisateur. Sinon, c'est un membre existant.
|
||||||
|
const inviteLink = inviteToken
|
||||||
|
? `https://www.choralsync.com/invite?token=${inviteToken}`
|
||||||
|
: `https://www.choralsync.com/app`; // Lien vers l'app pour accepter l'invitation interne
|
||||||
|
|
||||||
export default factories.createCoreService('api::mails.mails');
|
// 2. Récupérer le single-type "mails" avec l'API Document
|
||||||
|
const mailsConfig = await strapi.documents("api::mails.mails").findFirst({
|
||||||
|
populate: ["onInviteUser"],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!mailsConfig || !mailsConfig.onInviteUser) {
|
||||||
|
throw new Error(
|
||||||
|
"Le template d'email d'invitation n'est pas configuré dans le CMS.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const templateConfig = mailsConfig.onInviteUser[0];
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 3. Envoyer l'email via le moteur de template natif
|
||||||
|
await strapi.plugin("email").service("email").sendTemplatedEmail(
|
||||||
|
{
|
||||||
|
to: emailAddress,
|
||||||
|
from: "ChoralSync <contact@choralsync.com>",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
subject: templateConfig.subject,
|
||||||
|
html: templateConfig.message,
|
||||||
|
text: `Bonjour, Vous avez été invité(e) par <%= inviter_name %> à rejoindre <%= choir_name %>. Acceptez l'invitation en cliquant sur ce lien : <%= invite_link %>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Variables injectées dans le template (<%= variable %>)
|
||||||
|
inviter_name: inviterName,
|
||||||
|
choir_name: choirName,
|
||||||
|
invite_link: inviteLink,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return { success: true };
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erreur lors de l'envoi de l'email :", error);
|
||||||
|
// On throw l'erreur pour que le contrôleur puisse la logger,
|
||||||
|
// mais idéalement sans bloquer la création en base.
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -265,7 +265,7 @@
|
|||||||
"target": "api::order.order",
|
"target": "api::order.order",
|
||||||
"mappedBy": "user"
|
"mappedBy": "user"
|
||||||
},
|
},
|
||||||
"admin_tags": {
|
"smartTags": {
|
||||||
"type": "json"
|
"type": "json"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
types/generated/contentTypes.d.ts
vendored
12
types/generated/contentTypes.d.ts
vendored
@@ -401,7 +401,6 @@ export interface ApiAdAd extends Struct.CollectionTypeSchema {
|
|||||||
localizations: Schema.Attribute.Relation<'oneToMany', 'api::ad.ad'> &
|
localizations: Schema.Attribute.Relation<'oneToMany', 'api::ad.ad'> &
|
||||||
Schema.Attribute.Private;
|
Schema.Attribute.Private;
|
||||||
location: Schema.Attribute.Text;
|
location: Schema.Attribute.Text;
|
||||||
logo: Schema.Attribute.Media<'images' | 'files' | 'videos' | 'audios'>;
|
|
||||||
medias: Schema.Attribute.Media<
|
medias: Schema.Attribute.Media<
|
||||||
'images' | 'files' | 'videos' | 'audios',
|
'images' | 'files' | 'videos' | 'audios',
|
||||||
true
|
true
|
||||||
@@ -724,6 +723,8 @@ export interface ApiChoralMembershipChoralMembership
|
|||||||
createdAt: Schema.Attribute.DateTime;
|
createdAt: Schema.Attribute.DateTime;
|
||||||
createdBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> &
|
createdBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> &
|
||||||
Schema.Attribute.Private;
|
Schema.Attribute.Private;
|
||||||
|
invite_email: Schema.Attribute.Email & Schema.Attribute.Private;
|
||||||
|
invite_token: Schema.Attribute.String & Schema.Attribute.Private;
|
||||||
locale: Schema.Attribute.String & Schema.Attribute.Private;
|
locale: Schema.Attribute.String & Schema.Attribute.Private;
|
||||||
localizations: Schema.Attribute.Relation<
|
localizations: Schema.Attribute.Relation<
|
||||||
'oneToMany',
|
'oneToMany',
|
||||||
@@ -825,6 +826,7 @@ export interface ApiChoralChoral extends Struct.CollectionTypeSchema {
|
|||||||
'api::choral.choral'
|
'api::choral.choral'
|
||||||
> &
|
> &
|
||||||
Schema.Attribute.Private;
|
Schema.Attribute.Private;
|
||||||
|
logo: Schema.Attribute.Media<'images' | 'files' | 'videos' | 'audios'>;
|
||||||
memberships: Schema.Attribute.Relation<
|
memberships: Schema.Attribute.Relation<
|
||||||
'oneToMany',
|
'oneToMany',
|
||||||
'api::choral-membership.choral-membership'
|
'api::choral-membership.choral-membership'
|
||||||
@@ -1369,6 +1371,12 @@ export interface ApiMailsMails extends Struct.SingleTypeSchema {
|
|||||||
localized: true;
|
localized: true;
|
||||||
};
|
};
|
||||||
}>;
|
}>;
|
||||||
|
onInviteUser: Schema.Attribute.Component<'mail.mail', true> &
|
||||||
|
Schema.Attribute.SetPluginOptions<{
|
||||||
|
i18n: {
|
||||||
|
localized: true;
|
||||||
|
};
|
||||||
|
}>;
|
||||||
publishedAt: Schema.Attribute.DateTime;
|
publishedAt: Schema.Attribute.DateTime;
|
||||||
updatedAt: Schema.Attribute.DateTime;
|
updatedAt: Schema.Attribute.DateTime;
|
||||||
updatedBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> &
|
updatedBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> &
|
||||||
@@ -2132,7 +2140,6 @@ export interface PluginUsersPermissionsUser
|
|||||||
attributes: {
|
attributes: {
|
||||||
activities: Schema.Attribute.Component<'group.activity', true>;
|
activities: Schema.Attribute.Component<'group.activity', true>;
|
||||||
address: Schema.Attribute.Text;
|
address: Schema.Attribute.Text;
|
||||||
admin_tags: Schema.Attribute.JSON;
|
|
||||||
announcements: Schema.Attribute.Relation<
|
announcements: Schema.Attribute.Relation<
|
||||||
'oneToMany',
|
'oneToMany',
|
||||||
'api::announcement.announcement'
|
'api::announcement.announcement'
|
||||||
@@ -2226,6 +2233,7 @@ export interface PluginUsersPermissionsUser
|
|||||||
'plugin::users-permissions.role'
|
'plugin::users-permissions.role'
|
||||||
>;
|
>;
|
||||||
saved_posts: Schema.Attribute.Relation<'oneToMany', 'api::post.post'>;
|
saved_posts: Schema.Attribute.Relation<'oneToMany', 'api::post.post'>;
|
||||||
|
smartTags: Schema.Attribute.JSON;
|
||||||
subscriptionPlan: Schema.Attribute.Enumeration<['free', 'pro', 'premium']> &
|
subscriptionPlan: Schema.Attribute.Enumeration<['free', 'pro', 'premium']> &
|
||||||
Schema.Attribute.DefaultTo<'free'>;
|
Schema.Attribute.DefaultTo<'free'>;
|
||||||
surname: Schema.Attribute.String;
|
surname: Schema.Attribute.String;
|
||||||
|
|||||||
Reference in New Issue
Block a user