@webbio/strapi-plugin-page-builder 0.14.2-platform → 0.15.0-platform
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/server/bootstrap.js +7 -9
- package/dist/server/services/email.js +27 -27
- package/dist/server/services/private-content/graphql/resolvers/forgot-password.js +0 -2
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/server/bootstrap.ts +6 -8
- package/server/services/email.ts +40 -27
- package/server/services/private-content/graphql/resolvers/forgot-password.ts +0 -2
package/package.json
CHANGED
package/server/bootstrap.ts
CHANGED
|
@@ -36,13 +36,13 @@ export default async ({ strapi }: { strapi: Strapi }) => {
|
|
|
36
36
|
models: [USER_PERMISSION_USER_PLUGIN],
|
|
37
37
|
async beforeUpdate(event) {
|
|
38
38
|
if (event.params.data.id) {
|
|
39
|
-
const originalUserObject = await strapi.entityService?.findOne(
|
|
39
|
+
const originalUserObject = (await strapi.entityService?.findOne(
|
|
40
40
|
USER_PERMISSION_USER_PLUGIN,
|
|
41
41
|
event.params.data.id,
|
|
42
42
|
{
|
|
43
43
|
populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
|
|
44
44
|
}
|
|
45
|
-
)
|
|
45
|
+
)) as Record<string, any>;
|
|
46
46
|
|
|
47
47
|
if (
|
|
48
48
|
originalUserObject &&
|
|
@@ -51,13 +51,11 @@ export default async ({ strapi }: { strapi: Strapi }) => {
|
|
|
51
51
|
!originalUserObject.confirmMailSend
|
|
52
52
|
) {
|
|
53
53
|
await strapi.service(PAGE_BUILDER_EMAIL_PLUGIN).sendMail({
|
|
54
|
-
|
|
55
|
-
from: originalUserObject.platform.platformEmails.accountAcceptedMail.fromEmail,
|
|
54
|
+
from: originalUserObject.platform?.platformEmails?.accountAcceptedMail?.fromEmail,
|
|
56
55
|
to: event.params.data.email,
|
|
57
|
-
|
|
58
|
-
subject: originalUserObject.platform
|
|
59
|
-
|
|
60
|
-
text: originalUserObject.platform.platformEmails.accountAcceptedMail.message,
|
|
56
|
+
nameSender: originalUserObject.platform?.platformEmails?.accountAcceptedMail?.nameSender,
|
|
57
|
+
subject: originalUserObject.platform?.platformEmails?.accountAcceptedMail?.subject,
|
|
58
|
+
text: originalUserObject.platform?.platformEmails?.accountAcceptedMail?.message,
|
|
61
59
|
firstName: event.params.data.firstName,
|
|
62
60
|
lastName: event.params.data.lastName
|
|
63
61
|
});
|
package/server/services/email.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as AWS from '@aws-sdk/client-ses';
|
|
|
2
2
|
import { txtEmail } from './private-content/mail-template/txtMail.email.template.text';
|
|
3
3
|
import { USER_PERMISSION_USER_PLUGIN } from '../../shared/utils/constants';
|
|
4
4
|
import { errors } from '@strapi/utils';
|
|
5
|
+
import { Strapi } from '@strapi/strapi';
|
|
5
6
|
|
|
6
7
|
interface SendOptions {
|
|
7
8
|
from: string;
|
|
@@ -9,18 +10,21 @@ interface SendOptions {
|
|
|
9
10
|
subject: string;
|
|
10
11
|
text: string;
|
|
11
12
|
variables?: Record<string, string>;
|
|
13
|
+
nameSender?: string;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
export default {
|
|
15
17
|
async sendMail(options: SendOptions) {
|
|
16
|
-
const { from, to, subject, text, variables } = options;
|
|
18
|
+
const { from, to, subject, text, variables, nameSender } = options;
|
|
17
19
|
|
|
18
20
|
const emailData = txtEmail(text, variables);
|
|
19
21
|
|
|
22
|
+
const Source = nameSender ? `${nameSender} <${from}>` : from;
|
|
23
|
+
|
|
20
24
|
try {
|
|
21
25
|
const client = new AWS.SES();
|
|
22
26
|
await client.sendEmail({
|
|
23
|
-
Source
|
|
27
|
+
Source,
|
|
24
28
|
Destination: {
|
|
25
29
|
ToAddresses: [to]
|
|
26
30
|
},
|
|
@@ -37,17 +41,17 @@ export default {
|
|
|
37
41
|
}
|
|
38
42
|
},
|
|
39
43
|
async sendAdminMail(user) {
|
|
40
|
-
const foundUser = await strapi.entityService.findOne(USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
44
|
+
const foundUser = (await strapi.entityService.findOne(USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
41
45
|
populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
|
|
42
|
-
})
|
|
46
|
+
})) as Record<string, any>;
|
|
47
|
+
|
|
48
|
+
console.log('HI', foundUser?.platform?.platformEmails?.adminEmail?.fromEmail);
|
|
49
|
+
|
|
43
50
|
await this.sendMail({
|
|
44
|
-
// @ts-ignore we all love strapi typings
|
|
45
51
|
from: foundUser.platform.platformEmails.adminEmail.fromEmail,
|
|
46
|
-
// @ts-ignore
|
|
47
52
|
to: foundUser.platform.platformEmails.adminEmail.toEmail,
|
|
48
|
-
|
|
53
|
+
nameSender: user.platform.platformEmails.adminEmail.nameSender,
|
|
49
54
|
subject: foundUser.platform.platformEmails.adminEmail.subject,
|
|
50
|
-
// @ts-ignore
|
|
51
55
|
text: foundUser.platform.platformEmails.adminEmail.message,
|
|
52
56
|
variables: {
|
|
53
57
|
firstName: user.firstName,
|
|
@@ -56,37 +60,31 @@ export default {
|
|
|
56
60
|
});
|
|
57
61
|
},
|
|
58
62
|
async sendConfirmationEmail(user) {
|
|
59
|
-
const foundUser = await strapi.entityService.findOne(USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
63
|
+
const foundUser = (await strapi.entityService.findOne(USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
60
64
|
populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
|
|
61
|
-
})
|
|
65
|
+
})) as Record<string, any>;
|
|
66
|
+
|
|
62
67
|
if (foundUser && foundUser.platform) {
|
|
63
68
|
const jwtService = strapi.plugin('users-permissions').service('jwt');
|
|
64
69
|
const confirmationToken = await jwtService.issue(
|
|
65
|
-
// @ts-ignore
|
|
66
70
|
{ userId: user.id, platformId: foundUser.platform.id },
|
|
67
71
|
{ expiresIn: '1d' }
|
|
68
72
|
);
|
|
69
73
|
await strapi.entityService.update(USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
70
|
-
|
|
71
|
-
data: { confirmationToken: confirmationToken }
|
|
74
|
+
data: { confirmationToken: confirmationToken } as Record<string, any>
|
|
72
75
|
});
|
|
73
76
|
|
|
74
|
-
// @ts-ignore
|
|
75
77
|
const confirmEmailUrl = `${strapi.config.server.url}/api/page-builder/activate/${confirmationToken}`;
|
|
76
78
|
|
|
77
79
|
await this.sendMail({
|
|
78
|
-
// @ts-ignore
|
|
79
80
|
from: foundUser.platform.platformEmails.accountCreatedMail.fromEmail,
|
|
80
|
-
// @ts-ignore
|
|
81
81
|
to: foundUser.email,
|
|
82
|
-
|
|
82
|
+
nameSender: user.platform.platformEmails.accountCreatedMail.nameSender,
|
|
83
83
|
subject: foundUser.platform.platformEmails.accountCreatedMail.subject,
|
|
84
|
-
// @ts-ignore
|
|
85
84
|
text: foundUser.platform.platformEmails.accountCreatedMail.message,
|
|
86
85
|
variables: {
|
|
87
|
-
// @ts-ignore
|
|
88
86
|
firstName: foundUser.firstName,
|
|
89
|
-
|
|
87
|
+
|
|
90
88
|
lastName: foundUser.lastName,
|
|
91
89
|
confirmEmailUrl
|
|
92
90
|
}
|
|
@@ -102,20 +100,16 @@ export default {
|
|
|
102
100
|
{ expiresIn: '1d' }
|
|
103
101
|
);
|
|
104
102
|
await strapi.entityService.update(USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
105
|
-
|
|
106
|
-
data: { resetPasswordToken }
|
|
103
|
+
data: { resetPasswordToken } as Record<string, any>
|
|
107
104
|
});
|
|
108
105
|
|
|
109
|
-
|
|
110
|
-
const resetPasswordUrl = `${user.platform.domain}/wachtwoord-resetten/${resetPasswordToken}`;
|
|
106
|
+
const resetPasswordUrl = getResetPasswordUrl(user, resetPasswordToken);
|
|
111
107
|
|
|
112
108
|
await this.sendMail({
|
|
113
|
-
// @ts-ignore
|
|
114
109
|
from: user.platform.platformEmails.resetPasswordMail.fromEmail,
|
|
115
110
|
to: user.email,
|
|
116
|
-
|
|
111
|
+
nameSender: user.platform.platformEmails.resetPasswordMail.nameSender,
|
|
117
112
|
subject: user.platform.platformEmails.resetPasswordMail.subject,
|
|
118
|
-
// @ts-ignore
|
|
119
113
|
text: user.platform.platformEmails.resetPasswordMail.message,
|
|
120
114
|
variables: {
|
|
121
115
|
firstName: user?.firstName,
|
|
@@ -126,3 +120,22 @@ export default {
|
|
|
126
120
|
}
|
|
127
121
|
}
|
|
128
122
|
};
|
|
123
|
+
|
|
124
|
+
const getResetPasswordUrl = (user?: Record<string, any>, resetPasswordToken?: string) => {
|
|
125
|
+
if (!user || !user?.platform) {
|
|
126
|
+
return '';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (
|
|
130
|
+
user.platform.platformEmails.resetPasswordUrl &&
|
|
131
|
+
user.platform.platformEmails.resetPasswordUrl.includes('{{resetPasswordToken}}')
|
|
132
|
+
) {
|
|
133
|
+
const replacedTokens = user.platform.platformEmails.resetPasswordUrl
|
|
134
|
+
.replace('{{domain}}', user.platform.domain)
|
|
135
|
+
.replace('{{resetPasswordToken}}', resetPasswordToken);
|
|
136
|
+
|
|
137
|
+
return replacedTokens;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return `${user.platform.domain}/wachtwoord-resetten/${resetPasswordToken}`;
|
|
141
|
+
};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { errors } from '@strapi/utils';
|
|
2
1
|
import { USER_MODEL } from '../../constants';
|
|
3
2
|
import { validateForgotPasswordSchema } from '../../schemas';
|
|
4
|
-
const { UnauthorizedError } = errors;
|
|
5
3
|
|
|
6
4
|
export const platformForgotPassword = {
|
|
7
5
|
async resolve(parent, args, context) {
|