@webbio/strapi-plugin-page-builder 0.9.14-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.14-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({
@@ -7,18 +7,26 @@ export const platformForgotPassword = {
7
7
  async resolve(parent, args, context) {
8
8
  await validateForgotPasswordSchema(args.input);
9
9
 
10
- const { email, platformId } = args.input;
10
+ const { email, domain } = args.input;
11
11
 
12
12
  const user = await strapi.query(USER_MODEL).findOne({
13
13
  populate: { platform: { populate: { platformEmails: { populate: true } } } },
14
14
  where: {
15
15
  email: email.toLowerCase(),
16
16
  platform: {
17
- id: platformId
17
+ domain: domain.toLowerCase()
18
18
  }
19
19
  }
20
20
  });
21
+
22
+ if (!user) {
23
+ {
24
+ message: 'Email has been sent';
25
+ }
26
+ }
27
+
21
28
  await strapi.service('plugin::page-builder.email').sendForgotPasswordMail(user);
29
+
22
30
  return {
23
31
  message: 'Email has been sent'
24
32
  };
@@ -7,14 +7,17 @@ export const platformLogin = {
7
7
  async resolve(parent, args, context) {
8
8
  await validateLoginSchema(args.input);
9
9
 
10
- const { email, password, platformId } = args.input;
10
+ const { email, password, domain } = args.input;
11
11
 
12
12
  const user = await strapi.query(USER_MODEL).findOne({
13
13
  where: {
14
14
  email: email.toLowerCase(),
15
15
  platform: {
16
- id: platformId
16
+ domain: domain.toLowerCase()
17
17
  }
18
+ },
19
+ populate: {
20
+ platform: true
18
21
  }
19
22
  });
20
23
 
@@ -41,7 +44,9 @@ export const platformLogin = {
41
44
  const sanitizedUser = sanitize.contentAPI.output(user, strapi.getModel(USER_MODEL), {
42
45
  auth: false
43
46
  });
44
- const jwt = await strapi.service('plugin::users-permissions.jwt').issue({ id: user.id, platformId: platformId });
47
+ const jwt = await strapi
48
+ .service('plugin::users-permissions.jwt')
49
+ .issue({ id: user.id, platformId: user.platform.id });
45
50
 
46
51
  return {
47
52
  user: sanitizedUser,
@@ -2,7 +2,7 @@ import { sanitize } from '@strapi/utils';
2
2
  import { errors } from '@strapi/utils';
3
3
  import { USER_MODEL } from '../../constants';
4
4
  import { validateRegisterSchema } from '../../schemas';
5
- const { ApplicationError } = errors;
5
+ const { ApplicationError, NotFoundError } = errors;
6
6
 
7
7
  export const platformRegister = {
8
8
  async resolve(parent, args, context) {
@@ -11,7 +11,17 @@ export const platformRegister = {
11
11
 
12
12
  await validateRegisterSchema(args.input);
13
13
 
14
- const { email, platformId } = args.input;
14
+ const { email, domain } = args.input;
15
+
16
+ const platform = await strapi.query('api::platform.platform').findOne({
17
+ where: {
18
+ domain: domain.toLowerCase()
19
+ }
20
+ });
21
+
22
+ if (!platform) {
23
+ throw new NotFoundError('Platform not found');
24
+ }
15
25
 
16
26
  const role = await strapi
17
27
  .query('plugin::users-permissions.role')
@@ -24,11 +34,11 @@ export const platformRegister = {
24
34
  where: {
25
35
  $and: [
26
36
  {
27
- email
37
+ email: email.toLowerCase()
28
38
  },
29
39
  {
30
40
  platform: {
31
- id: platformId
41
+ id: platform.id
32
42
  }
33
43
  }
34
44
  ]
@@ -43,7 +53,7 @@ export const platformRegister = {
43
53
  ...args.input,
44
54
  role: role.id,
45
55
  categories: args.input.categories,
46
- platform: platformId,
56
+ platform: platform.id,
47
57
  email: email.toLowerCase(),
48
58
  provider: 'local',
49
59
  confirmed: false,
@@ -2,14 +2,14 @@ export const LoginInput = `
2
2
  input LoginInput {
3
3
  email: String!
4
4
  password: String!
5
- platformId: ID!
5
+ domain: String!
6
6
  }
7
7
  `;
8
8
 
9
9
  export const ForgotPasswordInput = `
10
10
  input ForgotPasswordInput {
11
11
  email: String!
12
- platformId: ID!
12
+ domain: String!
13
13
  }`;
14
14
 
15
15
  export const RegisterInput = `
@@ -27,7 +27,7 @@ input RegisterInput {
27
27
  phone: String
28
28
  subscribeToNewsletter: Boolean
29
29
  categories: [ID]
30
- platformId: ID!
30
+ domain: String!
31
31
  }
32
32
  `;
33
33
 
@@ -57,7 +57,6 @@ type User {
57
57
  confirmed: Boolean
58
58
  blocked: Boolean
59
59
  activated: Boolean
60
- platformId: ID!
61
60
  }
62
61
  `;
63
62
 
@@ -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() {
@@ -3,18 +3,18 @@ import { validateYupSchema, yup } from '@strapi/utils';
3
3
  const registerSchema = yup.object({
4
4
  email: yup.string().email().required(),
5
5
  password: yup.string().required(),
6
- platformId: yup.number().required()
6
+ domain: yup.string().required()
7
7
  });
8
8
 
9
9
  export const loginSchema = yup.object({
10
10
  email: yup.string().email().required(),
11
11
  password: yup.string().required(),
12
- platformId: yup.number().required()
12
+ domain: yup.string().required()
13
13
  });
14
14
 
15
15
  export const forgotPasswordSchema = yup.object({
16
16
  email: yup.string().email().required(),
17
- platformId: yup.number().required()
17
+ domain: yup.string().required()
18
18
  });
19
19
 
20
20
  export const resetPasswordSchema = yup.object({