@webbio/strapi-plugin-page-builder 0.9.15-authentication → 0.9.16-authentication

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.9.15-authentication",
3
+ "version": "0.9.16-authentication",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -1,10 +1,18 @@
1
- import { Strapi } from '@strapi/strapi';
1
+ import { Context } from 'koa';
2
2
 
3
3
  export default {
4
- activateUser(ctx) {
5
- return (strapi as Strapi).service('plugin::page-builder.private-content').activateUser(ctx.params.token);
4
+ async activateUser(ctx: Context): Promise<any> {
5
+ try {
6
+ const user = await strapi.service('plugin::page-builder.private-content').activateUser(ctx.params.token);
7
+ const callbackUrl = user.platform.emailConfirmationCallbackUrl;
8
+
9
+ return ctx.redirect('');
10
+ } catch (error) {
11
+ console.log(ctx);
12
+ return ctx.unauthorized('User is already confirmed or token is invalid');
13
+ }
6
14
  },
7
- removeInactiveUsers(ctx) {
8
- return (strapi as Strapi).service('plugin::page-builder.private-content').removeInactiveUsers();
15
+ removeInactiveUsers(ctx: Context) {
16
+ return strapi.service('plugin::page-builder.private-content').removeInactiveUsers();
9
17
  }
10
18
  };
@@ -22,8 +22,8 @@
22
22
  "repeatable": false,
23
23
  "component": "internal.platform-email"
24
24
  },
25
- "isPrivate": {
26
- "type": "boolean"
25
+ "emailConfirmationCallbackUrl": {
26
+ "type": "string"
27
27
  }
28
28
  }
29
29
  }
@@ -73,8 +73,9 @@ export default {
73
73
  // @ts-ignore
74
74
  data: { confirmationToken: confirmationToken }
75
75
  });
76
+
76
77
  // @ts-ignore
77
- const activateUrl = `${foundUser.platform.domain}/api/page-builder/activate/${confirmationToken}`;
78
+ const activateUrl = `${strapi.config.server.url}/api/page-builder/activate/${confirmationToken}`;
78
79
 
79
80
  await this.sendMail({
80
81
  // @ts-ignore
@@ -103,6 +104,7 @@ export default {
103
104
  data: { resetPasswordToken }
104
105
  });
105
106
 
107
+ // @ts-ignore
106
108
  const activateUrl = `${user.platform.domain}/api/page-builder/reset/${resetPasswordToken}`;
107
109
 
108
110
  await this.sendMail({
@@ -19,8 +19,6 @@ export const platformRegister = {
19
19
  }
20
20
  });
21
21
 
22
- console.log(platform);
23
-
24
22
  if (!platform) {
25
23
  throw new NotFoundError('Platform not found');
26
24
  }
@@ -19,29 +19,38 @@ export default {
19
19
  const pageBuilderConfig = getConfig();
20
20
  return pageBuilderConfig?.privateContent === true;
21
21
  },
22
- async activateUser(token: string) {
23
- const jwtService = strapi.plugin('users-permissions').service('jwt');
24
- const decodedToken = await jwtService.verify(token);
22
+ async activateUser(token: string): Promise<void> {
23
+ try {
24
+ const jwtService = strapi.plugin('users-permissions').service('jwt');
25
+ const decodedToken = await jwtService.verify(token);
25
26
 
26
- if (decodedToken) {
27
- const user = await strapi.query('plugin::users-permissions.user').findOne({
28
- where: {
29
- id: decodedToken.userId,
30
- platform: {
31
- id: decodedToken.platformId
27
+ if (decodedToken) {
28
+ const user = await strapi.query('plugin::users-permissions.user').findOne({
29
+ where: {
30
+ id: decodedToken.userId,
31
+ platform: {
32
+ id: decodedToken.platformId
33
+ }
34
+ },
35
+ populate: {
36
+ platform: true
32
37
  }
33
- }
34
- });
35
- if (!user.confirmed && user.confirmationToken && user.confirmationToken === token) {
36
- await strapi.entityService.update('plugin::users-permissions.user', user.id, {
37
- // @ts-ignore
38
- data: { confirmed: true, confirmationToken: null }
39
38
  });
40
- await strapi.service('plugin::page-builder.email').sendAdminMail(user);
41
39
 
42
- return ' User has been created';
40
+ if (user?.confirmed === false && user?.confirmationToken != null && user?.confirmationToken === token) {
41
+ await strapi.entityService.update('plugin::users-permissions.user', user.id, {
42
+ // @ts-ignore
43
+ data: { confirmed: true, confirmationToken: null }
44
+ });
45
+ await strapi.service('plugin::page-builder.email').sendAdminMail(user);
46
+ return user;
47
+ } else {
48
+ throw new Error("Error activating user. User doesn't exist or is already activated.");
49
+ }
43
50
  }
44
- throw new Error('User already activated');
51
+ } catch (error) {
52
+ console.error(error);
53
+ throw error;
45
54
  }
46
55
  },
47
56
  async removeInactiveUsers() {