@webbio/strapi-plugin-page-builder 0.9.8-platform → 0.9.9-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/README.md +30 -0
- package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +1 -1
- package/dist/package.json +8 -2
- package/dist/server/bootstrap.js +31 -1
- package/dist/server/content-types/category/schema.json +18 -0
- package/dist/server/content-types/index.js +9 -1
- package/dist/server/controllers/index.js +3 -1
- package/dist/server/controllers/private-content.js +10 -0
- package/dist/server/graphql/page-by-path.js +19 -2
- package/dist/server/register.js +13 -0
- package/dist/server/routes/index.js +17 -0
- package/dist/server/schema/page-end.json +8 -0
- package/dist/server/services/builder.js +86 -0
- package/dist/server/services/constants/customUserConstants.js +16 -0
- package/dist/server/services/custom-user.js +161 -0
- package/dist/server/services/email.js +127 -0
- package/dist/server/services/index.js +5 -1
- package/dist/server/services/private-content/auth.js +0 -0
- package/dist/server/services/private-content/components/admin-email.json +22 -0
- package/dist/server/services/private-content/components/email.json +22 -0
- package/dist/server/services/private-content/components/platform-email.json +30 -0
- package/dist/server/services/private-content/constants/index.js +16 -0
- package/dist/server/services/private-content/email.js +3 -0
- package/dist/server/services/private-content/graphql/index.js +77 -0
- package/dist/server/services/private-content/graphql/resolvers/findOnePage.js +40 -0
- package/dist/server/services/private-content/graphql/resolvers/findPage.js +43 -0
- package/dist/server/services/private-content/graphql/resolvers/forgot-password.js +26 -0
- package/dist/server/services/private-content/graphql/resolvers/login.js +44 -0
- package/dist/server/services/private-content/graphql/resolvers/register.js +60 -0
- package/dist/server/services/private-content/graphql/resolvers/reset-password.js +41 -0
- package/dist/server/services/private-content/graphql/types/index.js +91 -0
- package/dist/server/services/private-content/graphql.js +128 -0
- package/dist/server/services/private-content/hash.js +0 -0
- package/dist/server/services/private-content/index.js +81 -0
- package/dist/server/services/private-content/mail-template/txtMail.email.template.text.js +12 -0
- package/dist/server/services/private-content/mail-template/txtMail.interface.js +2 -0
- package/dist/server/services/private-content/page.js +17 -0
- package/dist/server/services/private-content/platform.js +17 -0
- package/dist/server/services/private-content/schemas/index.js +30 -0
- package/dist/server/services/private-content/user.js +159 -0
- package/dist/server/utils/strapi.js +9 -1
- package/dist/shared/utils/constants.js +3 -1
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +8 -2
- package/server/bootstrap.ts +39 -1
- package/server/content-types/category/schema.json +18 -0
- package/server/content-types/index.ts +7 -1
- package/server/controllers/index.ts +3 -1
- package/server/controllers/private-content.ts +10 -0
- package/server/graphql/page-by-path.ts +24 -2
- package/server/register.ts +14 -0
- package/server/routes/index.ts +17 -0
- package/server/schema/page-end.json +9 -1
- package/server/services/builder.ts +83 -1
- package/server/services/email.ts +122 -0
- package/server/services/index.ts +5 -1
- package/server/services/private-content/components/admin-email.json +23 -0
- package/server/services/private-content/components/email.json +23 -0
- package/server/services/private-content/components/platform-email.json +30 -0
- package/server/services/private-content/constants/index.ts +13 -0
- package/server/services/private-content/graphql/index.ts +88 -0
- package/server/services/private-content/graphql/resolvers/findOnePage.ts +40 -0
- package/server/services/private-content/graphql/resolvers/findPage.ts +45 -0
- package/server/services/private-content/graphql/resolvers/forgot-password.ts +26 -0
- package/server/services/private-content/graphql/resolvers/login.ts +51 -0
- package/server/services/private-content/graphql/resolvers/register.ts +68 -0
- package/server/services/private-content/graphql/resolvers/reset-password.ts +44 -0
- package/server/services/private-content/graphql/types/index.ts +98 -0
- package/server/services/private-content/index.ts +84 -0
- package/server/services/private-content/mail-template/txtMail.email.template.text.ts +7 -0
- package/server/services/private-content/mail-template/txtMail.interface.ts +7 -0
- package/server/services/private-content/page.ts +14 -0
- package/server/services/private-content/platform.ts +14 -0
- package/server/services/private-content/schemas/index.ts +28 -0
- package/server/services/private-content/user.ts +187 -0
- package/server/utils/strapi.ts +5 -0
- package/shared/utils/constants.ts +2 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const AWS = __importStar(require("@aws-sdk/client-ses"));
|
|
27
|
+
const txtMail_email_template_text_1 = require("./private-content/mail-template/txtMail.email.template.text");
|
|
28
|
+
const constants_1 = require("../../shared/utils/constants");
|
|
29
|
+
exports.default = {
|
|
30
|
+
async sendMail(options) {
|
|
31
|
+
const { from, to, subject, text, firstName, lastName, confirmationUrl } = options;
|
|
32
|
+
const emailData = (0, txtMail_email_template_text_1.txtEmail)({
|
|
33
|
+
email: to,
|
|
34
|
+
firstName: firstName,
|
|
35
|
+
lastName: lastName,
|
|
36
|
+
text: text,
|
|
37
|
+
confirmationUrl: confirmationUrl
|
|
38
|
+
});
|
|
39
|
+
try {
|
|
40
|
+
const client = new AWS.SES();
|
|
41
|
+
await client.sendEmail({
|
|
42
|
+
Source: from,
|
|
43
|
+
Destination: {
|
|
44
|
+
ToAddresses: [to]
|
|
45
|
+
},
|
|
46
|
+
Message: {
|
|
47
|
+
Subject: { Data: subject },
|
|
48
|
+
Body: {
|
|
49
|
+
Text: { Data: emailData }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error(error);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
async sendAdminMail(user) {
|
|
59
|
+
const foundUser = await strapi.entityService.findOne(constants_1.USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
60
|
+
populate: { platform: { populate: { platformMails: { populate: '*' } } } }
|
|
61
|
+
});
|
|
62
|
+
await this.sendMail({
|
|
63
|
+
// @ts-ignore we all love strapi typings
|
|
64
|
+
from: foundUser.platform.platformMails.adminEmail.fromEmail,
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
to: foundUser.platform.platformMails.adminEmail.toMail,
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
subject: foundUser.platform.platformMails.adminEmail.subject,
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
text: foundUser.platform.platformMails.adminEmail.message,
|
|
71
|
+
firstName: user.firstName,
|
|
72
|
+
lastName: user.lastName
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
async sendConfirmationEmail(user) {
|
|
76
|
+
const foundUser = await strapi.entityService.findOne(constants_1.USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
77
|
+
populate: { platform: { populate: { platformMails: { populate: '*' } } } }
|
|
78
|
+
});
|
|
79
|
+
if (foundUser && foundUser.platform) {
|
|
80
|
+
const jwtService = strapi.plugin('users-permissions').service('jwt');
|
|
81
|
+
const confirmationToken = await jwtService.issue(
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
{ userId: user.id, platformId: foundUser.platform.id }, { expiresIn: '1d' });
|
|
84
|
+
await strapi.entityService.update(constants_1.USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
data: { confirmationToken: confirmationToken }
|
|
87
|
+
});
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
const activateUrl = `${foundUser.platform.domain}/api/page-builder/activate/${confirmationToken}`;
|
|
90
|
+
await this.sendMail({
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
from: foundUser.platform.platformMails.accountCreatedMail.fromEmail,
|
|
93
|
+
to: user.email,
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
subject: foundUser.platform.platformMails.accountCreatedMail.subject,
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
text: foundUser.platform.platformMails.accountCreatedMail.message,
|
|
98
|
+
firstName: user.firstName,
|
|
99
|
+
lastName: user.lastName,
|
|
100
|
+
confirmationUrl: activateUrl
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
async sendForgotPasswordMail(user) {
|
|
105
|
+
if (user && user.platform) {
|
|
106
|
+
const jwtService = strapi.plugin('users-permissions').service('jwt');
|
|
107
|
+
const resetPasswordToken = await jwtService.issue({ userId: user.id, platformId: user.platform.id }, { expiresIn: '1d' });
|
|
108
|
+
await strapi.entityService.update(constants_1.USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
data: { resetPasswordToken }
|
|
111
|
+
});
|
|
112
|
+
const activateUrl = `${user.platform.domain}/api/page-builder/reset/${resetPasswordToken}`;
|
|
113
|
+
await this.sendMail({
|
|
114
|
+
// @ts-ignore
|
|
115
|
+
from: user.platform.platformMails.resetPasswordMail.fromEmail,
|
|
116
|
+
to: user.email,
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
subject: user.platform.platformMails.resetPasswordMail.subject,
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
text: user.platform.platformMails.resetPasswordMail.message,
|
|
121
|
+
firstName: user.firstName,
|
|
122
|
+
lastName: user.lastName,
|
|
123
|
+
confirmationUrl: activateUrl
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
@@ -9,11 +9,15 @@ const page_type_1 = __importDefault(require("./page-type"));
|
|
|
9
9
|
const collection_types_1 = __importDefault(require("./collection-types"));
|
|
10
10
|
const template_1 = __importDefault(require("./template"));
|
|
11
11
|
const platform_1 = __importDefault(require("./platform"));
|
|
12
|
+
const email_1 = __importDefault(require("./email"));
|
|
13
|
+
const private_content_1 = __importDefault(require("./private-content"));
|
|
12
14
|
exports.default = {
|
|
13
15
|
page: page_1.default,
|
|
14
16
|
builder: builder_1.default,
|
|
15
17
|
'page-type': page_type_1.default,
|
|
16
18
|
'collection-types': collection_types_1.default,
|
|
17
19
|
template: template_1.default,
|
|
18
|
-
platform: platform_1.default
|
|
20
|
+
platform: platform_1.default,
|
|
21
|
+
email: email_1.default,
|
|
22
|
+
'private-content': private_content_1.default
|
|
19
23
|
};
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"collectionName": "components_internal_admin_emails",
|
|
3
|
+
"info": {
|
|
4
|
+
"displayName": "AdminEmail",
|
|
5
|
+
"description": ""
|
|
6
|
+
},
|
|
7
|
+
"options": {},
|
|
8
|
+
"attributes": {
|
|
9
|
+
"toMail": {
|
|
10
|
+
"type": "string"
|
|
11
|
+
},
|
|
12
|
+
"fromEmail": {
|
|
13
|
+
"type": "string"
|
|
14
|
+
},
|
|
15
|
+
"subject": {
|
|
16
|
+
"type": "string"
|
|
17
|
+
},
|
|
18
|
+
"message": {
|
|
19
|
+
"type": "text"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"collectionName": "components_internal_emails",
|
|
3
|
+
"info": {
|
|
4
|
+
"displayName": "email",
|
|
5
|
+
"description": ""
|
|
6
|
+
},
|
|
7
|
+
"options": {},
|
|
8
|
+
"attributes": {
|
|
9
|
+
"nameSender": {
|
|
10
|
+
"type": "string"
|
|
11
|
+
},
|
|
12
|
+
"fromEmail": {
|
|
13
|
+
"type": "string"
|
|
14
|
+
},
|
|
15
|
+
"subject": {
|
|
16
|
+
"type": "string"
|
|
17
|
+
},
|
|
18
|
+
"message": {
|
|
19
|
+
"type": "text"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"collectionName": "components_internal_platform_emails",
|
|
3
|
+
"info": {
|
|
4
|
+
"displayName": "PlatformEmail"
|
|
5
|
+
},
|
|
6
|
+
"options": {},
|
|
7
|
+
"attributes": {
|
|
8
|
+
"resetPasswordMail": {
|
|
9
|
+
"type": "component",
|
|
10
|
+
"repeatable": false,
|
|
11
|
+
"component": "internal.email"
|
|
12
|
+
},
|
|
13
|
+
"accountCreatedMail": {
|
|
14
|
+
"type": "component",
|
|
15
|
+
"repeatable": false,
|
|
16
|
+
"component": "internal.email"
|
|
17
|
+
},
|
|
18
|
+
"accountAcceptedMail": {
|
|
19
|
+
"type": "component",
|
|
20
|
+
"repeatable": false,
|
|
21
|
+
"component": "internal.email"
|
|
22
|
+
},
|
|
23
|
+
"adminEmail": {
|
|
24
|
+
"displayName": "AdminEmail",
|
|
25
|
+
"type": "component",
|
|
26
|
+
"repeatable": false,
|
|
27
|
+
"component": "internal.admin-email"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ACTIONS = exports.CONTENT_ENTITY_MANAGER = exports.USER_ROLE = exports.USER_CONTENT_MANAGER = exports.USER_MODEL = exports.CREATED_BY_ATTRIBUTE = exports.UPDATED_BY_ATTRIBUTE = void 0;
|
|
5
|
+
const utils_1 = require("@strapi/utils");
|
|
6
|
+
_a = utils_1.contentTypes.constants, exports.UPDATED_BY_ATTRIBUTE = _a.UPDATED_BY_ATTRIBUTE, exports.CREATED_BY_ATTRIBUTE = _a.CREATED_BY_ATTRIBUTE;
|
|
7
|
+
exports.USER_MODEL = 'plugin::users-permissions.user';
|
|
8
|
+
exports.USER_CONTENT_MANAGER = 'plugin::users-permissions.contentmanageruser';
|
|
9
|
+
exports.USER_ROLE = 'plugin::users-permissions.role';
|
|
10
|
+
exports.CONTENT_ENTITY_MANAGER = 'plugin::content-manager.entity-manager';
|
|
11
|
+
exports.ACTIONS = {
|
|
12
|
+
read: 'plugin::content-manager.explorer.read',
|
|
13
|
+
create: 'plugin::content-manager.explorer.create',
|
|
14
|
+
edit: 'plugin::content-manager.explorer.update',
|
|
15
|
+
delete: 'plugin::content-manager.explorer.delete'
|
|
16
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extendGraphQL = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const register_1 = require("./resolvers/register");
|
|
6
|
+
const login_1 = require("./resolvers/login");
|
|
7
|
+
const forgot_password_1 = require("./resolvers/forgot-password");
|
|
8
|
+
const reset_password_1 = require("./resolvers/reset-password");
|
|
9
|
+
const findOnePage_1 = require("./resolvers/findOnePage");
|
|
10
|
+
const findPage_1 = require("./resolvers/findPage");
|
|
11
|
+
const extendGraphQL = () => {
|
|
12
|
+
const extensionService = strapi.plugin('graphql').service('extension');
|
|
13
|
+
const extension = () => ({
|
|
14
|
+
typeDefs: `
|
|
15
|
+
${types_1.RegisterInput}
|
|
16
|
+
|
|
17
|
+
${types_1.LoginInput}
|
|
18
|
+
|
|
19
|
+
${types_1.RegisterResponse}
|
|
20
|
+
|
|
21
|
+
${types_1.LoginResponse}
|
|
22
|
+
|
|
23
|
+
${types_1.User}
|
|
24
|
+
|
|
25
|
+
${types_1.Mutations}
|
|
26
|
+
|
|
27
|
+
${types_1.ForgotPasswordInput}
|
|
28
|
+
|
|
29
|
+
${types_1.ForgotPasswordResponse}
|
|
30
|
+
|
|
31
|
+
${types_1.ResetPasswordInput}
|
|
32
|
+
|
|
33
|
+
${types_1.ResetPasswordResponse}
|
|
34
|
+
|
|
35
|
+
${types_1.ResetPasswordInput}
|
|
36
|
+
|
|
37
|
+
${types_1.ResetPasswordResponse}
|
|
38
|
+
|
|
39
|
+
${types_1.Queries}
|
|
40
|
+
|
|
41
|
+
`,
|
|
42
|
+
resolvers: {
|
|
43
|
+
Query: {
|
|
44
|
+
page: findOnePage_1.page,
|
|
45
|
+
pages: findPage_1.pages
|
|
46
|
+
},
|
|
47
|
+
Mutation: {
|
|
48
|
+
platformLogin: login_1.platformLogin,
|
|
49
|
+
platformRegister: register_1.platformRegister,
|
|
50
|
+
platformForgotPassword: forgot_password_1.platformForgotPassword,
|
|
51
|
+
platformResetPassword: reset_password_1.platformResetPassword
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
resolversConfig: {
|
|
55
|
+
'Mutation.platformLogin': {
|
|
56
|
+
auth: false
|
|
57
|
+
},
|
|
58
|
+
'Mutation.platformRegister': {
|
|
59
|
+
auth: false
|
|
60
|
+
},
|
|
61
|
+
'Mutation.platformForgotPassword': {
|
|
62
|
+
auth: false
|
|
63
|
+
},
|
|
64
|
+
'Mutation.platformResetPassword': {
|
|
65
|
+
auth: false
|
|
66
|
+
},
|
|
67
|
+
'Query.page': {
|
|
68
|
+
auth: false
|
|
69
|
+
},
|
|
70
|
+
'Query.pages': {
|
|
71
|
+
auth: false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
extensionService.use(extension);
|
|
76
|
+
};
|
|
77
|
+
exports.extendGraphQL = extendGraphQL;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.page = void 0;
|
|
4
|
+
const fp_1 = require("lodash/fp");
|
|
5
|
+
const utils_1 = require("@strapi/utils");
|
|
6
|
+
const constants_1 = require("../../../../../shared/utils/constants");
|
|
7
|
+
const apollo_server_koa_1 = require("apollo-server-koa");
|
|
8
|
+
exports.page = {
|
|
9
|
+
async resolve(parent, args, ctx) {
|
|
10
|
+
var _a, _b, _c, _d;
|
|
11
|
+
const uid = constants_1.PAGE_UID;
|
|
12
|
+
const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
|
|
13
|
+
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
14
|
+
const populatedArgs = { ...args, populate: { platform: true } };
|
|
15
|
+
const transformedArgs = transformArgs(populatedArgs, strapi.contentType(constants_1.PAGE_UID));
|
|
16
|
+
const sanitizedQuery = await utils_1.sanitize.contentAPI.query(populatedArgs, strapi.contentType(constants_1.PAGE_UID));
|
|
17
|
+
const value = await strapi.entityService.findOne(uid, args.id, (0, fp_1.omit)('id', sanitizedQuery));
|
|
18
|
+
// @ts-ignore Strapi types are the best
|
|
19
|
+
if (!((_a = value === null || value === void 0 ? void 0 : value.platform) === null || _a === void 0 ? void 0 : _a.isPrivate) && !value.isPrivate) {
|
|
20
|
+
return toEntityResponse(value, { args: transformedArgs, resourceUID: uid });
|
|
21
|
+
}
|
|
22
|
+
if (
|
|
23
|
+
// @ts-ignore Strapi types are the best
|
|
24
|
+
(((_b = value === null || value === void 0 ? void 0 : value.platform) === null || _b === void 0 ? void 0 : _b.isPrivate) === true && ctx.koaContext.req.headers.authorization) ||
|
|
25
|
+
((value === null || value === void 0 ? void 0 : value.isPrivate) === true && ctx.koaContext.req.headers.authorization)) {
|
|
26
|
+
const auth = ctx.koaContext.req.headers.authorization;
|
|
27
|
+
const token = auth.split(' ');
|
|
28
|
+
const jwtService = strapi.plugin('users-permissions').service('jwt');
|
|
29
|
+
const decodedToken = await jwtService.verify(token[1]);
|
|
30
|
+
if (decodedToken) {
|
|
31
|
+
const user = ctx.state.user;
|
|
32
|
+
// @ts-ignore Strapi types are the best
|
|
33
|
+
if (((_c = user === null || user === void 0 ? void 0 : user.platform) === null || _c === void 0 ? void 0 : _c.id) === ((_d = value === null || value === void 0 ? void 0 : value.platform) === null || _d === void 0 ? void 0 : _d.id)) {
|
|
34
|
+
return toEntityResponse(value, { args: transformedArgs, resourceUID: uid });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return new apollo_server_koa_1.ForbiddenError('Forbidden access');
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pages = void 0;
|
|
4
|
+
const utils_1 = require("@strapi/utils");
|
|
5
|
+
const constants_1 = require("../../../../../shared/utils/constants");
|
|
6
|
+
exports.pages = {
|
|
7
|
+
async resolve(parent, args, ctx) {
|
|
8
|
+
const uid = constants_1.PAGE_UID;
|
|
9
|
+
const { toEntityResponseCollection } = strapi.plugin('graphql').service('format').returnTypes;
|
|
10
|
+
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
11
|
+
const populatedArgs = { ...args, populate: { platform: true } };
|
|
12
|
+
const transformedArgs = transformArgs(populatedArgs, strapi.contentType(constants_1.PAGE_UID));
|
|
13
|
+
const sanitizedQuery = await utils_1.sanitize.contentAPI.query(populatedArgs, strapi.contentType(constants_1.PAGE_UID));
|
|
14
|
+
const value = await strapi.entityService.findMany(uid, sanitizedQuery);
|
|
15
|
+
const user = ctx.state.user;
|
|
16
|
+
if (user && ctx.koaContext.req.headers.authorization) {
|
|
17
|
+
const auth = ctx.koaContext.req.headers.authorization;
|
|
18
|
+
const token = auth.split(' ');
|
|
19
|
+
const jwtService = strapi.plugin('users-permissions').service('jwt');
|
|
20
|
+
const decodedToken = await jwtService.verify(token[1]);
|
|
21
|
+
if (decodedToken) {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
const filteredItems = value.filter((item) => {
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
if (item.platform.isPrivate === true && user.platform.id === item.platform.id) {
|
|
26
|
+
return item;
|
|
27
|
+
}
|
|
28
|
+
if (item.isPrivate === true && user.platform.id === item.platform.id) {
|
|
29
|
+
return item;
|
|
30
|
+
}
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
if (item.platform.isPrivate !== true && item.isPrivate !== true) {
|
|
33
|
+
return item;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return toEntityResponseCollection(filteredItems, { args: transformedArgs, resourceUID: uid });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
const filteredItems = value.filter((item) => item.platform.isPrivate !== true && item.isPrivate !== true);
|
|
41
|
+
return toEntityResponseCollection(filteredItems, { args: transformedArgs, resourceUID: uid });
|
|
42
|
+
}
|
|
43
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.platformForgotPassword = void 0;
|
|
4
|
+
const utils_1 = require("@strapi/utils");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
const schemas_1 = require("../../schemas");
|
|
7
|
+
const { UnauthorizedError } = utils_1.errors;
|
|
8
|
+
exports.platformForgotPassword = {
|
|
9
|
+
async resolve(parent, args, context) {
|
|
10
|
+
await (0, schemas_1.validateForgotPasswordSchema)(args.input);
|
|
11
|
+
const { email, platformId } = args.input;
|
|
12
|
+
const user = await strapi.query(constants_1.USER_MODEL).findOne({
|
|
13
|
+
populate: { platform: { populate: { platformMails: { populate: true } } } },
|
|
14
|
+
where: {
|
|
15
|
+
email: email.toLowerCase(),
|
|
16
|
+
platform: {
|
|
17
|
+
id: platformId
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
await strapi.service('plugin::page-builder.email').sendForgotPasswordMail(user);
|
|
22
|
+
return {
|
|
23
|
+
message: 'Email has been sent'
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.platformLogin = void 0;
|
|
4
|
+
const utils_1 = require("@strapi/utils");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
const schemas_1 = require("../../schemas");
|
|
7
|
+
const { UnauthorizedError } = utils_1.errors;
|
|
8
|
+
exports.platformLogin = {
|
|
9
|
+
async resolve(parent, args, context) {
|
|
10
|
+
await (0, schemas_1.validateLoginSchema)(args.input);
|
|
11
|
+
const { email, password, platformId } = args.input;
|
|
12
|
+
const user = await strapi.query(constants_1.USER_MODEL).findOne({
|
|
13
|
+
where: {
|
|
14
|
+
email: email.toLowerCase(),
|
|
15
|
+
platform: {
|
|
16
|
+
id: platformId
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
if (user == null) {
|
|
21
|
+
throw new UnauthorizedError('Invalid email or password');
|
|
22
|
+
}
|
|
23
|
+
const isPasswordValid = await strapi
|
|
24
|
+
.service('plugin::users-permissions.user')
|
|
25
|
+
.validatePassword(password, user.password);
|
|
26
|
+
if (isPasswordValid === false) {
|
|
27
|
+
throw new UnauthorizedError('Invalid email or password');
|
|
28
|
+
}
|
|
29
|
+
if (user.confirmed === false) {
|
|
30
|
+
throw new UnauthorizedError('Email is not confirmed');
|
|
31
|
+
}
|
|
32
|
+
if (user.activateUser === false) {
|
|
33
|
+
throw new UnauthorizedError('Account is not activated');
|
|
34
|
+
}
|
|
35
|
+
const sanitizedUser = utils_1.sanitize.contentAPI.output(user, strapi.getModel(constants_1.USER_MODEL), {
|
|
36
|
+
auth: false
|
|
37
|
+
});
|
|
38
|
+
const jwt = await strapi.service('plugin::users-permissions.jwt').issue({ id: user.id, platformId: platformId });
|
|
39
|
+
return {
|
|
40
|
+
user: sanitizedUser,
|
|
41
|
+
jwt
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.platformRegister = void 0;
|
|
4
|
+
const utils_1 = require("@strapi/utils");
|
|
5
|
+
const utils_2 = require("@strapi/utils");
|
|
6
|
+
const constants_1 = require("../../constants");
|
|
7
|
+
const schemas_1 = require("../../schemas");
|
|
8
|
+
const { ApplicationError } = utils_2.errors;
|
|
9
|
+
exports.platformRegister = {
|
|
10
|
+
async resolve(parent, args, context) {
|
|
11
|
+
const pluginStore = await strapi.store({ type: 'plugin', name: 'users-permissions' });
|
|
12
|
+
const settings = await pluginStore.get({ key: 'advanced' });
|
|
13
|
+
await (0, schemas_1.validateRegisterSchema)(args.input);
|
|
14
|
+
const { email, platformId } = args.input;
|
|
15
|
+
const role = await strapi
|
|
16
|
+
.query('plugin::users-permissions.role')
|
|
17
|
+
.findOne({ where: { type: settings.default_role } });
|
|
18
|
+
if (!role) {
|
|
19
|
+
throw new ApplicationError('Impossible to find the default role');
|
|
20
|
+
}
|
|
21
|
+
const conflictingUserCount = await strapi.query(constants_1.USER_MODEL).count({
|
|
22
|
+
where: {
|
|
23
|
+
$and: [
|
|
24
|
+
{
|
|
25
|
+
email
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
platform: {
|
|
29
|
+
id: platformId
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (conflictingUserCount > 0) {
|
|
36
|
+
throw new ApplicationError('Email is already taken');
|
|
37
|
+
}
|
|
38
|
+
const userData = {
|
|
39
|
+
...args.input,
|
|
40
|
+
role: role.id,
|
|
41
|
+
categories: args.input.categories,
|
|
42
|
+
platform: platformId,
|
|
43
|
+
email: email.toLowerCase(),
|
|
44
|
+
provider: 'local',
|
|
45
|
+
confirmed: false,
|
|
46
|
+
activateUser: false
|
|
47
|
+
};
|
|
48
|
+
const createdUser = await strapi.entityService.create(constants_1.USER_MODEL, {
|
|
49
|
+
data: userData
|
|
50
|
+
});
|
|
51
|
+
const userModel = strapi.getModel(constants_1.USER_MODEL);
|
|
52
|
+
const sanitizedUser = utils_1.sanitize.contentAPI.output(createdUser, userModel, {
|
|
53
|
+
auth: false
|
|
54
|
+
});
|
|
55
|
+
await strapi.service('plugin::page-builder.email').sendConfirmationEmail(createdUser);
|
|
56
|
+
return {
|
|
57
|
+
user: sanitizedUser
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.platformResetPassword = void 0;
|
|
4
|
+
const utils_1 = require("@strapi/utils");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
const schemas_1 = require("../../schemas");
|
|
7
|
+
exports.platformResetPassword = {
|
|
8
|
+
async resolve(parent, args, context) {
|
|
9
|
+
await (0, schemas_1.validateResetPasswordSchema)(args.input);
|
|
10
|
+
const { password, resetPasswordToken } = args.input;
|
|
11
|
+
const jwtService = strapi.plugin('users-permissions').service('jwt');
|
|
12
|
+
const decodedToken = await jwtService.verify(resetPasswordToken);
|
|
13
|
+
if (decodedToken) {
|
|
14
|
+
const user = await strapi.query(constants_1.USER_MODEL).findOne({
|
|
15
|
+
where: {
|
|
16
|
+
id: decodedToken.userId,
|
|
17
|
+
resetPasswordToken: resetPasswordToken
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
if (user && user.resetPasswordToken && user.resetPasswordToken === resetPasswordToken) {
|
|
21
|
+
if (password) {
|
|
22
|
+
await strapi.entityService.update(constants_1.USER_MODEL, user.id, {
|
|
23
|
+
data: {
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
password: password,
|
|
26
|
+
resetPasswordToken: null
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const userModel = strapi.getModel(constants_1.USER_MODEL);
|
|
31
|
+
const sanitizedUser = utils_1.sanitize.contentAPI.output(user, userModel, {
|
|
32
|
+
auth: false
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
user: sanitizedUser
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
throw new Error('Time of token has expired request a new password change');
|
|
40
|
+
}
|
|
41
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Queries = exports.Mutations = exports.ResetPasswordResponse = exports.ResetPasswordInput = exports.ResetPassword = exports.User = exports.ForgotPasswordResponse = exports.RegisterResponse = exports.LoginResponse = exports.RegisterInput = exports.ForgotPasswordInput = exports.LoginInput = void 0;
|
|
4
|
+
exports.LoginInput = `
|
|
5
|
+
input LoginInput {
|
|
6
|
+
email: String!
|
|
7
|
+
password: String!
|
|
8
|
+
platformId: ID!
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
exports.ForgotPasswordInput = `
|
|
12
|
+
input ForgotPasswordInput {
|
|
13
|
+
email: String!
|
|
14
|
+
platformId: ID!
|
|
15
|
+
}`;
|
|
16
|
+
exports.RegisterInput = `
|
|
17
|
+
input RegisterInput {
|
|
18
|
+
email: String!
|
|
19
|
+
password: String!
|
|
20
|
+
firstName: String
|
|
21
|
+
lastName: String
|
|
22
|
+
company: String
|
|
23
|
+
jobTitle: String
|
|
24
|
+
address: String
|
|
25
|
+
postalCode: String
|
|
26
|
+
city: String
|
|
27
|
+
country: String
|
|
28
|
+
phone: String
|
|
29
|
+
subscribeToNewsletter: Boolean
|
|
30
|
+
categories: [ID]
|
|
31
|
+
platformId: ID!
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
exports.LoginResponse = `
|
|
35
|
+
type LoginResponse {
|
|
36
|
+
jwt: String
|
|
37
|
+
user: User
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
exports.RegisterResponse = `
|
|
41
|
+
type RegisterResponse {
|
|
42
|
+
user: User
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
exports.ForgotPasswordResponse = `
|
|
46
|
+
type ForgotPasswordResponse {
|
|
47
|
+
message: String
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
exports.User = `
|
|
51
|
+
type User {
|
|
52
|
+
id: ID!
|
|
53
|
+
email: String!
|
|
54
|
+
confirmed: Boolean
|
|
55
|
+
blocked: Boolean
|
|
56
|
+
activated: Boolean
|
|
57
|
+
platformId: ID!
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
exports.ResetPassword = `
|
|
61
|
+
type ResetPassword {
|
|
62
|
+
jwt: String
|
|
63
|
+
email: String
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
exports.ResetPasswordInput = `
|
|
67
|
+
input ResetPasswordInput {
|
|
68
|
+
password: String!
|
|
69
|
+
passwordConfirmation: String!
|
|
70
|
+
resetPasswordToken: String!
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
exports.ResetPasswordResponse = `
|
|
74
|
+
type ResetPasswordResponse {
|
|
75
|
+
user: User
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
78
|
+
exports.Mutations = `
|
|
79
|
+
type Mutation {
|
|
80
|
+
platformLogin(input: LoginInput!): LoginResponse
|
|
81
|
+
platformRegister(input: RegisterInput!): RegisterResponse
|
|
82
|
+
platformForgotPassword(input: ForgotPasswordInput!): ForgotPasswordResponse
|
|
83
|
+
platformResetPassword(input: ResetPasswordInput!): ResetPasswordResponse
|
|
84
|
+
}
|
|
85
|
+
`;
|
|
86
|
+
exports.Queries = `
|
|
87
|
+
type Query {
|
|
88
|
+
page(id: ID, locale: I18NLocaleCode): PageEntityResponse
|
|
89
|
+
pages(filters: PageFiltersInput pagination: PaginationArg = {} sort: [String] = [] publicationState: PublicationState = LIVE locale: I18NLocaleCode): PageEntityResponseCollection
|
|
90
|
+
}
|
|
91
|
+
`;
|