@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/dist/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,8 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = {
4
- activateUser(ctx) {
5
- return strapi.service('plugin::page-builder.private-content').activateUser(ctx.params.token);
4
+ async activateUser(ctx) {
5
+ try {
6
+ const user = await strapi.service('plugin::page-builder.private-content').activateUser(ctx.params.token);
7
+ const callbackUrl = user.platform.emailConfirmationCallbackUrl;
8
+ return ctx.redirect('');
9
+ }
10
+ catch (error) {
11
+ console.log(ctx);
12
+ return ctx.unauthorized('User is already confirmed or token is invalid');
13
+ }
6
14
  },
7
15
  removeInactiveUsers(ctx) {
8
16
  return strapi.service('plugin::page-builder.private-content').removeInactiveUsers();
@@ -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
  }
@@ -86,7 +86,7 @@ exports.default = {
86
86
  data: { confirmationToken: confirmationToken }
87
87
  });
88
88
  // @ts-ignore
89
- const activateUrl = `${foundUser.platform.domain}/api/page-builder/activate/${confirmationToken}`;
89
+ const activateUrl = `${strapi.config.server.url}/api/page-builder/activate/${confirmationToken}`;
90
90
  await this.sendMail({
91
91
  // @ts-ignore
92
92
  from: foundUser.platform.platformEmails.accountCreatedMail.fromEmail,
@@ -109,6 +109,7 @@ exports.default = {
109
109
  // @ts-ignore
110
110
  data: { resetPasswordToken }
111
111
  });
112
+ // @ts-ignore
112
113
  const activateUrl = `${user.platform.domain}/api/page-builder/reset/${resetPasswordToken}`;
113
114
  await this.sendMail({
114
115
  // @ts-ignore
@@ -8,16 +8,21 @@ const { UnauthorizedError } = utils_1.errors;
8
8
  exports.platformForgotPassword = {
9
9
  async resolve(parent, args, context) {
10
10
  await (0, schemas_1.validateForgotPasswordSchema)(args.input);
11
- const { email, platformId } = args.input;
11
+ const { email, domain } = args.input;
12
12
  const user = await strapi.query(constants_1.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
+ if (!user) {
22
+ {
23
+ message: 'Email has been sent';
24
+ }
25
+ }
21
26
  await strapi.service('plugin::page-builder.email').sendForgotPasswordMail(user);
22
27
  return {
23
28
  message: 'Email has been sent'
@@ -8,13 +8,16 @@ const { UnauthorizedError } = utils_1.errors;
8
8
  exports.platformLogin = {
9
9
  async resolve(parent, args, context) {
10
10
  await (0, schemas_1.validateLoginSchema)(args.input);
11
- const { email, password, platformId } = args.input;
11
+ const { email, password, domain } = args.input;
12
12
  const user = await strapi.query(constants_1.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
  if (user == null) {
@@ -35,7 +38,9 @@ exports.platformLogin = {
35
38
  const sanitizedUser = utils_1.sanitize.contentAPI.output(user, strapi.getModel(constants_1.USER_MODEL), {
36
39
  auth: false
37
40
  });
38
- const jwt = await strapi.service('plugin::users-permissions.jwt').issue({ id: user.id, platformId: platformId });
41
+ const jwt = await strapi
42
+ .service('plugin::users-permissions.jwt')
43
+ .issue({ id: user.id, platformId: user.platform.id });
39
44
  return {
40
45
  user: sanitizedUser,
41
46
  jwt
@@ -5,13 +5,21 @@ const utils_1 = require("@strapi/utils");
5
5
  const utils_2 = require("@strapi/utils");
6
6
  const constants_1 = require("../../constants");
7
7
  const schemas_1 = require("../../schemas");
8
- const { ApplicationError } = utils_2.errors;
8
+ const { ApplicationError, NotFoundError } = utils_2.errors;
9
9
  exports.platformRegister = {
10
10
  async resolve(parent, args, context) {
11
11
  const pluginStore = await strapi.store({ type: 'plugin', name: 'users-permissions' });
12
12
  const settings = await pluginStore.get({ key: 'advanced' });
13
13
  await (0, schemas_1.validateRegisterSchema)(args.input);
14
- const { email, platformId } = args.input;
14
+ const { email, domain } = args.input;
15
+ const platform = await strapi.query('api::platform.platform').findOne({
16
+ where: {
17
+ domain: domain.toLowerCase()
18
+ }
19
+ });
20
+ if (!platform) {
21
+ throw new NotFoundError('Platform not found');
22
+ }
15
23
  const role = await strapi
16
24
  .query('plugin::users-permissions.role')
17
25
  .findOne({ where: { type: settings.default_role } });
@@ -22,11 +30,11 @@ exports.platformRegister = {
22
30
  where: {
23
31
  $and: [
24
32
  {
25
- email
33
+ email: email.toLowerCase()
26
34
  },
27
35
  {
28
36
  platform: {
29
- id: platformId
37
+ id: platform.id
30
38
  }
31
39
  }
32
40
  ]
@@ -39,7 +47,7 @@ exports.platformRegister = {
39
47
  ...args.input,
40
48
  role: role.id,
41
49
  categories: args.input.categories,
42
- platform: platformId,
50
+ platform: platform.id,
43
51
  email: email.toLowerCase(),
44
52
  provider: 'local',
45
53
  confirmed: false,
@@ -5,13 +5,13 @@ exports.LoginInput = `
5
5
  input LoginInput {
6
6
  email: String!
7
7
  password: String!
8
- platformId: ID!
8
+ domain: String!
9
9
  }
10
10
  `;
11
11
  exports.ForgotPasswordInput = `
12
12
  input ForgotPasswordInput {
13
13
  email: String!
14
- platformId: ID!
14
+ domain: String!
15
15
  }`;
16
16
  exports.RegisterInput = `
17
17
  input RegisterInput {
@@ -28,7 +28,7 @@ input RegisterInput {
28
28
  phone: String
29
29
  subscribeToNewsletter: Boolean
30
30
  categories: [ID]
31
- platformId: ID!
31
+ domain: String!
32
32
  }
33
33
  `;
34
34
  exports.LoginResponse = `
@@ -54,7 +54,6 @@ type User {
54
54
  confirmed: Boolean
55
55
  blocked: Boolean
56
56
  activated: Boolean
57
- platformId: ID!
58
57
  }
59
58
  `;
60
59
  exports.ResetPassword = `
@@ -22,26 +22,37 @@ exports.default = {
22
22
  return (pageBuilderConfig === null || pageBuilderConfig === void 0 ? void 0 : pageBuilderConfig.privateContent) === true;
23
23
  },
24
24
  async activateUser(token) {
25
- const jwtService = strapi.plugin('users-permissions').service('jwt');
26
- const decodedToken = await jwtService.verify(token);
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
25
+ try {
26
+ const jwtService = strapi.plugin('users-permissions').service('jwt');
27
+ const decodedToken = await jwtService.verify(token);
28
+ if (decodedToken) {
29
+ const user = await strapi.query('plugin::users-permissions.user').findOne({
30
+ where: {
31
+ id: decodedToken.userId,
32
+ platform: {
33
+ id: decodedToken.platformId
34
+ }
35
+ },
36
+ populate: {
37
+ platform: true
33
38
  }
34
- }
35
- });
36
- if (!user.confirmed && user.confirmationToken && user.confirmationToken === token) {
37
- await strapi.entityService.update('plugin::users-permissions.user', user.id, {
38
- // @ts-ignore
39
- data: { confirmed: true, confirmationToken: null }
40
39
  });
41
- await strapi.service('plugin::page-builder.email').sendAdminMail(user);
42
- return ' User has been created';
40
+ if ((user === null || user === void 0 ? void 0 : user.confirmed) === false && (user === null || user === void 0 ? void 0 : user.confirmationToken) != null && (user === null || user === void 0 ? void 0 : 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
+ }
48
+ else {
49
+ throw new Error("Error activating user. User doesn't exist or is already activated.");
50
+ }
43
51
  }
44
- throw new Error('User already activated');
52
+ }
53
+ catch (error) {
54
+ console.error(error);
55
+ throw error;
45
56
  }
46
57
  },
47
58
  async removeInactiveUsers() {
@@ -5,16 +5,16 @@ const utils_1 = require("@strapi/utils");
5
5
  const registerSchema = utils_1.yup.object({
6
6
  email: utils_1.yup.string().email().required(),
7
7
  password: utils_1.yup.string().required(),
8
- platformId: utils_1.yup.number().required()
8
+ domain: utils_1.yup.string().required()
9
9
  });
10
10
  exports.loginSchema = utils_1.yup.object({
11
11
  email: utils_1.yup.string().email().required(),
12
12
  password: utils_1.yup.string().required(),
13
- platformId: utils_1.yup.number().required()
13
+ domain: utils_1.yup.string().required()
14
14
  });
15
15
  exports.forgotPasswordSchema = utils_1.yup.object({
16
16
  email: utils_1.yup.string().email().required(),
17
- platformId: utils_1.yup.number().required()
17
+ domain: utils_1.yup.string().required()
18
18
  });
19
19
  exports.resetPasswordSchema = utils_1.yup.object({
20
20
  password: utils_1.yup.string().required(),