|
1 | | -// import type { Core } from '@strapi/strapi'; |
| 1 | +import type { Core } from "@strapi/strapi"; |
2 | 2 |
|
3 | 3 | export default { |
4 | | - /** |
5 | | - * An asynchronous register function that runs before |
6 | | - * your application is initialized. |
7 | | - * |
8 | | - * This gives you an opportunity to extend code. |
9 | | - */ |
10 | | - register(/* { strapi }: { strapi: Core.Strapi } */) {}, |
| 4 | + register(/* { strapi }: { strapi: Core.Strapi } */) {}, |
11 | 5 |
|
12 | | - /** |
13 | | - * An asynchronous bootstrap function that runs before |
14 | | - * your application gets started. |
15 | | - * |
16 | | - * This gives you an opportunity to set up your data model, |
17 | | - * run jobs, or perform some special logic. |
18 | | - */ |
19 | | - bootstrap(/* { strapi }: { strapi: Core.Strapi } */) {}, |
| 6 | + bootstrap({ strapi }: { strapi: Core.Strapi }) { |
| 7 | + strapi.db.lifecycles.subscribe({ |
| 8 | + models: ["admin::user"], |
| 9 | + async afterCreate(event) { |
| 10 | + const { result } = event; |
| 11 | + if (!result.registrationToken || !result.email) return; |
| 12 | + |
| 13 | + const url = strapi.config.get("server.url") as string; |
| 14 | + if (!url) return; |
| 15 | + |
| 16 | + const registrationUrl = `${url}/admin/auth/register?registrationToken=${result.registrationToken}`; |
| 17 | + |
| 18 | + try { |
| 19 | + await strapi |
| 20 | + .plugin("email") |
| 21 | + .service("email") |
| 22 | + .send({ |
| 23 | + to: result.email, |
| 24 | + subject: "You have been invited to Garmeres Strapi", |
| 25 | + text: `Hi!\n\nYou have been invited to Garmeres Strapi, the content management tool for the Garmeres website.\n\nClick the link below to create your account:\n${registrationUrl}`, |
| 26 | + html: `<p>Hi!</p><p>You have been invited to Garmeres Strapi, the content management tool for the Garmeres website.</p><p><a href="${registrationUrl}">Click here to create your account</a></p>`, |
| 27 | + }); |
| 28 | + } catch (err) { |
| 29 | + strapi.log.error("Failed to send invite email:", err); |
| 30 | + } |
| 31 | + }, |
| 32 | + }); |
| 33 | + }, |
20 | 34 | }; |
0 commit comments