@webbio/strapi-plugin-page-builder 0.15.0-platform → 0.15.2-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.15.0-platform",
3
+ "version": "0.15.2-platform",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -36,30 +36,37 @@ 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(
40
- USER_PERMISSION_USER_PLUGIN,
41
- event.params.data.id,
42
- {
43
- populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
44
- }
45
- )) as Record<string, any>;
39
+ try {
40
+ const originalUserObject = (await strapi.entityService?.findOne(
41
+ USER_PERMISSION_USER_PLUGIN,
42
+ event.params.data.id,
43
+ {
44
+ populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
45
+ }
46
+ )) as Record<string, any>;
46
47
 
47
- if (
48
- originalUserObject &&
49
- event.params.data.activateUser &&
50
- event.params.data.confirmed &&
51
- !originalUserObject.confirmMailSend
52
- ) {
53
- await strapi.service(PAGE_BUILDER_EMAIL_PLUGIN).sendMail({
54
- from: originalUserObject.platform?.platformEmails?.accountAcceptedMail?.fromEmail,
55
- to: event.params.data.email,
56
- nameSender: originalUserObject.platform?.platformEmails?.accountAcceptedMail?.nameSender,
57
- subject: originalUserObject.platform?.platformEmails?.accountAcceptedMail?.subject,
58
- text: originalUserObject.platform?.platformEmails?.accountAcceptedMail?.message,
59
- firstName: event.params.data.firstName,
60
- lastName: event.params.data.lastName
61
- });
62
- event.params.data.confirmMailSend = true;
48
+ if (
49
+ originalUserObject &&
50
+ event.params.data.activateUser &&
51
+ event.params.data.confirmed &&
52
+ !originalUserObject.confirmMailSend
53
+ ) {
54
+ const send = await strapi.service(PAGE_BUILDER_EMAIL_PLUGIN).sendMail({
55
+ from: originalUserObject.platform?.platformEmails?.accountAcceptedMail?.fromEmail,
56
+ to: event.params.data.email,
57
+ nameSender: originalUserObject.platform?.platformEmails?.accountAcceptedMail?.nameSender,
58
+ subject: originalUserObject.platform?.platformEmails?.accountAcceptedMail?.subject,
59
+ text: originalUserObject.platform?.platformEmails?.accountAcceptedMail?.message,
60
+ firstName: event.params.data.firstName,
61
+ lastName: event.params.data.lastName
62
+ });
63
+
64
+ if (send) {
65
+ event.params.data.confirmMailSend = true;
66
+ }
67
+ }
68
+ } catch (e) {
69
+ console.error('Send Account Approved Mail Error:', e);
63
70
  }
64
71
  }
65
72
  }
@@ -35,88 +35,111 @@ export default {
35
35
  }
36
36
  }
37
37
  });
38
+
39
+ return true;
38
40
  } catch (error) {
39
41
  console.error(error);
40
42
  throw new errors.ApplicationError('Failed to send email', error);
41
43
  }
42
44
  },
43
45
  async sendAdminMail(user) {
44
- const foundUser = (await strapi.entityService.findOne(USER_PERMISSION_USER_PLUGIN, user.id, {
45
- populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
46
- })) as Record<string, any>;
47
-
48
- console.log('HI', foundUser?.platform?.platformEmails?.adminEmail?.fromEmail);
49
-
50
- await this.sendMail({
51
- from: foundUser.platform.platformEmails.adminEmail.fromEmail,
52
- to: foundUser.platform.platformEmails.adminEmail.toEmail,
53
- nameSender: user.platform.platformEmails.adminEmail.nameSender,
54
- subject: foundUser.platform.platformEmails.adminEmail.subject,
55
- text: foundUser.platform.platformEmails.adminEmail.message,
56
- variables: {
57
- firstName: user.firstName,
58
- lastName: user.lastName
59
- }
60
- });
61
- },
62
- async sendConfirmationEmail(user) {
63
- const foundUser = (await strapi.entityService.findOne(USER_PERMISSION_USER_PLUGIN, user.id, {
64
- populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
65
- })) as Record<string, any>;
66
-
67
- if (foundUser && foundUser.platform) {
68
- const jwtService = strapi.plugin('users-permissions').service('jwt');
69
- const confirmationToken = await jwtService.issue(
70
- { userId: user.id, platformId: foundUser.platform.id },
71
- { expiresIn: '1d' }
72
- );
73
- await strapi.entityService.update(USER_PERMISSION_USER_PLUGIN, user.id, {
74
- data: { confirmationToken: confirmationToken } as Record<string, any>
75
- });
46
+ try {
47
+ const foundUser = (await strapi.entityService.findOne(USER_PERMISSION_USER_PLUGIN, user.id, {
48
+ populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
49
+ })) as Record<string, any>;
76
50
 
77
- const confirmEmailUrl = `${strapi.config.server.url}/api/page-builder/activate/${confirmationToken}`;
51
+ if (!foundUser?.platform?.platformEmails?.adminEmail?.fromEmail) {
52
+ throw new Error('Account Admin Mail is not configured');
53
+ }
78
54
 
79
55
  await this.sendMail({
80
- from: foundUser.platform.platformEmails.accountCreatedMail.fromEmail,
81
- to: foundUser.email,
82
- nameSender: user.platform.platformEmails.accountCreatedMail.nameSender,
83
- subject: foundUser.platform.platformEmails.accountCreatedMail.subject,
84
- text: foundUser.platform.platformEmails.accountCreatedMail.message,
56
+ from: foundUser?.platform?.platformEmails?.adminEmail?.fromEmail,
57
+ to: foundUser?.platform?.platformEmails?.adminEmail?.toEmail,
58
+ nameSender: foundUser?.platform.platformEmails.adminEmail.nameSender,
59
+ subject: foundUser?.platform?.platformEmails?.adminEmail?.subject,
60
+ text: foundUser?.platform?.platformEmails?.adminEmail?.message,
85
61
  variables: {
86
- firstName: foundUser.firstName,
87
-
88
- lastName: foundUser.lastName,
89
- confirmEmailUrl
62
+ firstName: user.firstName,
63
+ lastName: user.lastName
90
64
  }
91
65
  });
66
+ } catch (e) {
67
+ console.error('Send Admin Mail Error:', e);
92
68
  }
93
69
  },
94
- async sendForgotPasswordMail(user) {
95
- if (user && user.platform) {
96
- const jwtService = strapi.plugin('users-permissions').service('jwt');
97
-
98
- const resetPasswordToken = await jwtService.issue(
99
- { userId: user.id, platformId: user.platform.id },
100
- { expiresIn: '1d' }
101
- );
102
- await strapi.entityService.update(USER_PERMISSION_USER_PLUGIN, user.id, {
103
- data: { resetPasswordToken } as Record<string, any>
104
- });
105
-
106
- const resetPasswordUrl = getResetPasswordUrl(user, resetPasswordToken);
70
+ async sendConfirmationEmail(user) {
71
+ try {
72
+ const foundUser = (await strapi.entityService.findOne(USER_PERMISSION_USER_PLUGIN, user.id, {
73
+ populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
74
+ })) as Record<string, any>;
75
+
76
+ if (foundUser && foundUser.platform) {
77
+ const jwtService = strapi.plugin('users-permissions').service('jwt');
78
+ const confirmationToken = await jwtService.issue(
79
+ { userId: user.id, platformId: foundUser.platform.id },
80
+ { expiresIn: '1d' }
81
+ );
82
+ await strapi.entityService.update(USER_PERMISSION_USER_PLUGIN, user.id, {
83
+ data: { confirmationToken: confirmationToken } as Record<string, any>
84
+ });
85
+
86
+ const confirmEmailUrl = `${strapi.config.server.url}/api/page-builder/activate/${confirmationToken}`;
87
+
88
+ if (!foundUser?.platform?.platformEmails?.accountCreatedMail?.fromEmail) {
89
+ throw new Error('Account Confirmation Mail is not configured');
90
+ }
107
91
 
108
- await this.sendMail({
109
- from: user.platform.platformEmails.resetPasswordMail.fromEmail,
110
- to: user.email,
111
- nameSender: user.platform.platformEmails.resetPasswordMail.nameSender,
112
- subject: user.platform.platformEmails.resetPasswordMail.subject,
113
- text: user.platform.platformEmails.resetPasswordMail.message,
114
- variables: {
115
- firstName: user?.firstName,
116
- lastName: user?.lastName,
117
- resetPasswordUrl
92
+ await this.sendMail({
93
+ from: foundUser?.platform?.platformEmails?.accountCreatedMail?.fromEmail,
94
+ to: foundUser?.email,
95
+ nameSender: foundUser?.platform?.platformEmails?.accountCreatedMail?.nameSender,
96
+ subject: foundUser?.platform?.platformEmails?.accountCreatedMail?.subject,
97
+ text: foundUser?.platform?.platformEmails?.accountCreatedMail?.message,
98
+ variables: {
99
+ firstName: foundUser?.firstName,
100
+ lastName: foundUser?.lastName,
101
+ confirmEmailUrl
102
+ }
103
+ });
104
+ }
105
+ } catch (e) {
106
+ console.error('Send Confirmation Mail Error:', e);
107
+ }
108
+ },
109
+ async sendForgotPasswordMail(user) {
110
+ try {
111
+ if (user && user.platform) {
112
+ const jwtService = strapi.plugin('users-permissions').service('jwt');
113
+
114
+ const resetPasswordToken = await jwtService.issue(
115
+ { userId: user.id, platformId: user.platform.id },
116
+ { expiresIn: '1d' }
117
+ );
118
+ await strapi.entityService.update(USER_PERMISSION_USER_PLUGIN, user.id, {
119
+ data: { resetPasswordToken } as Record<string, any>
120
+ });
121
+
122
+ if (!user?.platform?.platformEmails?.resetPasswordMail?.fromEmail) {
123
+ throw new Error('Forgot Password Mail is not configured');
118
124
  }
119
- });
125
+
126
+ const resetPasswordUrl = getResetPasswordUrl(user, resetPasswordToken);
127
+
128
+ await this.sendMail({
129
+ from: user.platform.platformEmails.resetPasswordMail.fromEmail,
130
+ to: user.email,
131
+ nameSender: user.platform.platformEmails.resetPasswordMail.nameSender,
132
+ subject: user.platform.platformEmails.resetPasswordMail.subject,
133
+ text: user.platform.platformEmails.resetPasswordMail.message,
134
+ variables: {
135
+ firstName: user?.firstName,
136
+ lastName: user?.lastName,
137
+ resetPasswordUrl
138
+ }
139
+ });
140
+ }
141
+ } catch (e) {
142
+ console.error('Send Forgot Password Mail Error:', e);
120
143
  }
121
144
  }
122
145
  };
@@ -127,15 +150,15 @@ const getResetPasswordUrl = (user?: Record<string, any>, resetPasswordToken?: st
127
150
  }
128
151
 
129
152
  if (
130
- user.platform.platformEmails.resetPasswordUrl &&
131
- user.platform.platformEmails.resetPasswordUrl.includes('{{resetPasswordToken}}')
153
+ user?.platform?.platformEmails?.resetPasswordUrl &&
154
+ user?.platform?.platformEmails?.resetPasswordUrl.includes('{{resetPasswordToken}}')
132
155
  ) {
133
156
  const replacedTokens = user.platform.platformEmails.resetPasswordUrl
134
- .replace('{{domain}}', user.platform.domain)
157
+ .replace('{{domain}}', user?.platform?.domain)
135
158
  .replace('{{resetPasswordToken}}', resetPasswordToken);
136
159
 
137
160
  return replacedTokens;
138
161
  }
139
162
 
140
- return `${user.platform.domain}/wachtwoord-resetten/${resetPasswordToken}`;
163
+ return `${user?.platform?.domain}/wachtwoord-resetten/${resetPasswordToken}`;
141
164
  };
@@ -25,6 +25,9 @@
25
25
  "type": "component",
26
26
  "repeatable": false,
27
27
  "component": "internal.admin-email"
28
+ },
29
+ "resetPasswordUrl": {
30
+ "type": "string"
28
31
  }
29
32
  }
30
33
  }