@webbio/strapi-plugin-page-builder 0.10.9-platform → 0.11.10-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/README.md +38 -1
- package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +1 -1
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +5 -1
- package/admin/src/components/PageTypeEditView/index.tsx +17 -6
- package/admin/src/index.tsx +2 -2
- package/admin/src/utils/hooks/usePlatformFormData.ts +8 -2
- 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 +18 -0
- package/dist/server/controllers/sitemap.js +20 -0
- package/dist/server/graphql/page-by-path.js +22 -2
- package/dist/server/policies/index.js +7 -1
- package/dist/server/policies/isAuthorizedPage.js +11 -0
- package/dist/server/register.js +2 -0
- package/dist/server/routes/index.js +17 -0
- package/dist/server/schema/page-end.json +8 -0
- package/dist/server/schema/platform-start.json +5 -0
- package/dist/server/services/builder.js +86 -0
- package/dist/server/services/email.js +132 -0
- package/dist/server/services/index.js +5 -1
- 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/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 +44 -0
- package/dist/server/services/private-content/graphql/resolvers/forgot-password.js +31 -0
- package/dist/server/services/private-content/graphql/resolvers/login.js +49 -0
- package/dist/server/services/private-content/graphql/resolvers/register.js +68 -0
- package/dist/server/services/private-content/graphql/resolvers/reset-password.js +41 -0
- package/dist/server/services/private-content/graphql/types/index.js +89 -0
- package/dist/server/services/private-content/index.js +92 -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/services/sitemap.js +17 -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 +17 -0
- package/server/graphql/page-by-path.ts +28 -2
- package/server/policies/index.ts +5 -1
- package/server/policies/isAuthorizedPage.ts +11 -0
- package/server/register.ts +2 -0
- package/server/routes/index.ts +17 -0
- package/server/schema/page-end.json +8 -0
- package/server/schema/platform-start.json +5 -0
- package/server/services/builder.ts +83 -1
- package/server/services/email.ts +127 -0
- package/server/services/index.ts +5 -1
- package/server/services/private-content/components/admin-email.json +22 -0
- package/server/services/private-content/components/email.json +22 -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 +34 -0
- package/server/services/private-content/graphql/resolvers/login.ts +56 -0
- package/server/services/private-content/graphql/resolvers/register.ts +78 -0
- package/server/services/private-content/graphql/resolvers/reset-password.ts +44 -0
- package/server/services/private-content/graphql/types/index.ts +96 -0
- package/server/services/private-content/index.ts +93 -0
- package/server/services/private-content/mail-template/txtMail.email.template.text.ts +6 -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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webbio/strapi-plugin-page-builder",
|
|
3
|
-
"version": "0.10
|
|
3
|
+
"version": "0.11.10-platform",
|
|
4
4
|
"description": "This is the description of the plugin.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"develop": "tsc -p tsconfig.server.json -w",
|
|
@@ -20,14 +20,20 @@
|
|
|
20
20
|
"url": "https://github.com/webbio/strapi-plugin-page-builder.git"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"@aws-sdk/client-ses": "^3.485.0",
|
|
23
24
|
"@mantine/hooks": "^7.2.2",
|
|
24
25
|
"@strapi/design-system": "^1.11.0",
|
|
25
26
|
"@strapi/helper-plugin": "^4.15.0",
|
|
26
27
|
"@strapi/icons": "^1.11.0",
|
|
28
|
+
"@strapi/provider-email-amazon-ses": "^4.16.2",
|
|
27
29
|
"@strapi/typescript-utils": "^4.15.0",
|
|
28
30
|
"@strapi/utils": "^4.15.0",
|
|
31
|
+
"add": "^2.0.6",
|
|
32
|
+
"aws-sdk": "^2.1528.0",
|
|
33
|
+
"handlebars": "^4.7.8",
|
|
29
34
|
"react-select": "^5.7.4",
|
|
30
|
-
"slugify": "^1.6.6"
|
|
35
|
+
"slugify": "^1.6.6",
|
|
36
|
+
"yarn": "^1.22.21"
|
|
31
37
|
},
|
|
32
38
|
"devDependencies": {
|
|
33
39
|
"@types/react": "^18.2.21",
|
package/server/bootstrap.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Common, Strapi } from '@strapi/strapi';
|
|
2
2
|
import { errors } from '@strapi/utils';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
PAGE_BUILDER_EMAIL_PLUGIN,
|
|
5
|
+
PAGE_TYPE_UID,
|
|
6
|
+
PAGE_UID,
|
|
7
|
+
PLATFORM_UID,
|
|
8
|
+
USER_PERMISSION_USER_PLUGIN
|
|
9
|
+
} from '../shared/utils/constants';
|
|
4
10
|
import permissions from './bootstrap/permissions';
|
|
5
11
|
import collectionTypeLifecycles from './bootstrap/collection-type-lifecycles';
|
|
6
12
|
|
|
@@ -20,6 +26,38 @@ export default async ({ strapi }: { strapi: Strapi }) => {
|
|
|
20
26
|
return data;
|
|
21
27
|
};
|
|
22
28
|
|
|
29
|
+
const plugin = strapi.plugin('users-permissions');
|
|
30
|
+
|
|
31
|
+
plugin.services.user.fetchAuthenticatedUser = async (id: any) => {
|
|
32
|
+
return strapi.query('plugin::users-permissions.user').findOne({ where: { id }, populate: ['role', 'platform'] });
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
strapi.db?.lifecycles.subscribe({
|
|
36
|
+
models: [USER_PERMISSION_USER_PLUGIN],
|
|
37
|
+
async beforeUpdate(event) {
|
|
38
|
+
if (event.params.data.id) {
|
|
39
|
+
const userToUpdate = await strapi.entityService?.findOne(USER_PERMISSION_USER_PLUGIN, event.params.data.id, {
|
|
40
|
+
populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
|
|
41
|
+
});
|
|
42
|
+
if (userToUpdate) {
|
|
43
|
+
if (event.params.data.activateUser && event.params.data.confirmed && !userToUpdate.confirmMailSend) {
|
|
44
|
+
await strapi.service(PAGE_BUILDER_EMAIL_PLUGIN).sendMail({
|
|
45
|
+
// @ts-ignore strapi typings
|
|
46
|
+
from: userToUpdate.platform.platformEmails.accountAcceptedMail.fromEmail,
|
|
47
|
+
to: event.params.data.email,
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
subject: userToUpdate.platform.platformEmails.accountAcceptedMail.subject,
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
text: userToUpdate.platform.platformEmails.accountAcceptedMail.message,
|
|
52
|
+
firstName: event.params.data.firstName,
|
|
53
|
+
lastName: event.params.data.lastName
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
23
61
|
strapi.db?.lifecycles.subscribe({
|
|
24
62
|
// @ts-ignore
|
|
25
63
|
models: [PAGE_UID],
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kind": "collectionType",
|
|
3
|
+
"collectionName": "categories",
|
|
4
|
+
"info": {
|
|
5
|
+
"singularName": "category",
|
|
6
|
+
"pluralName": "categories",
|
|
7
|
+
"displayName": "category"
|
|
8
|
+
},
|
|
9
|
+
"options": {
|
|
10
|
+
"draftAndPublish": false,
|
|
11
|
+
"comment": ""
|
|
12
|
+
},
|
|
13
|
+
"attributes": {
|
|
14
|
+
"title": {
|
|
15
|
+
"type": "string"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -3,11 +3,13 @@ import pageType from './page-type';
|
|
|
3
3
|
import collectionTypes from './collection-types';
|
|
4
4
|
import template from './template';
|
|
5
5
|
import platform from './platform';
|
|
6
|
+
import privateContent from './private-content';
|
|
6
7
|
|
|
7
8
|
export default {
|
|
8
9
|
page,
|
|
9
10
|
'page-type': pageType,
|
|
10
11
|
'collection-types': collectionTypes,
|
|
11
12
|
template,
|
|
12
|
-
platform
|
|
13
|
+
platform,
|
|
14
|
+
'private-content': privateContent
|
|
13
15
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context } from 'koa';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
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.domain}/inloggen`;
|
|
8
|
+
return ctx.redirect(callbackUrl);
|
|
9
|
+
} catch (error) {
|
|
10
|
+
console.log(ctx);
|
|
11
|
+
return ctx.unauthorized('User is already confirmed or token is invalid');
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
removeInactiveUsers(ctx: Context) {
|
|
15
|
+
return strapi.service('plugin::page-builder.private-content').removeInactiveUsers();
|
|
16
|
+
}
|
|
17
|
+
};
|
|
@@ -2,6 +2,9 @@ import { Strapi } from '@strapi/strapi';
|
|
|
2
2
|
|
|
3
3
|
import { PAGE_UID } from '../../shared/utils/constants';
|
|
4
4
|
|
|
5
|
+
import { ForbiddenError as ApolloForbiddenError } from 'apollo-server-koa';
|
|
6
|
+
import { getConfig } from '../utils/strapi';
|
|
7
|
+
|
|
5
8
|
const getPageByPath = (strapi: Strapi) => {
|
|
6
9
|
const typeDefs = () => {
|
|
7
10
|
return `
|
|
@@ -34,7 +37,6 @@ const getPageByPath = (strapi: Strapi) => {
|
|
|
34
37
|
};
|
|
35
38
|
|
|
36
39
|
const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
|
|
37
|
-
|
|
38
40
|
const getPage = async () => {
|
|
39
41
|
const transformedArgs = transformArgs(filteredArgs, {
|
|
40
42
|
contentType: strapi.contentTypes[PAGE_UID],
|
|
@@ -75,7 +77,28 @@ const getPageByPath = (strapi: Strapi) => {
|
|
|
75
77
|
const results: Record<string, any> = await getPage();
|
|
76
78
|
|
|
77
79
|
if (Object.values(results)?.filter(Boolean).length > 0) {
|
|
78
|
-
|
|
80
|
+
if (!results?.platform?.isPrivate && !results?.isPrivate) {
|
|
81
|
+
return results;
|
|
82
|
+
}
|
|
83
|
+
if (
|
|
84
|
+
(results?.platform?.isPrivate === true && ctx.koaContext.req.headers.authorization) ||
|
|
85
|
+
(results?.isPrivate === true && ctx.koaContext.req.headers.authorization)
|
|
86
|
+
) {
|
|
87
|
+
const auth = ctx.koaContext.req.headers.authorization;
|
|
88
|
+
const token = auth.split(' ');
|
|
89
|
+
|
|
90
|
+
const jwtService = strapi.plugin('users-permissions').service('jwt');
|
|
91
|
+
const decodedToken = await jwtService.verify(token[1]);
|
|
92
|
+
if (decodedToken) {
|
|
93
|
+
const user = ctx.state.user;
|
|
94
|
+
|
|
95
|
+
if (user?.platform?.id === results?.platform?.id) {
|
|
96
|
+
return results;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return new ApolloForbiddenError('Forbidden access');
|
|
79
102
|
} else {
|
|
80
103
|
throw new Error(ctx.koaContext.response.message);
|
|
81
104
|
}
|
|
@@ -90,8 +113,11 @@ const getPageByPath = (strapi: Strapi) => {
|
|
|
90
113
|
};
|
|
91
114
|
};
|
|
92
115
|
|
|
116
|
+
const pageBuilderConfig = getConfig();
|
|
117
|
+
|
|
93
118
|
const resolversConfig = {
|
|
94
119
|
'Query.getPageByPath': {
|
|
120
|
+
policies: pageBuilderConfig?.privateContent === true ? ['plugin::page-builder.isAuthorizedForPage'] : [],
|
|
95
121
|
auth: false
|
|
96
122
|
}
|
|
97
123
|
};
|
package/server/policies/index.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const isAuthorizedForPage = (policyContext, _config, { strapi }) => {
|
|
2
|
+
const pageToken = policyContext.http.request.headers['x-strapi-page-secret'];
|
|
3
|
+
const pageEnvToken = process.env.STRAPI_PAGE_SECRET;
|
|
4
|
+
|
|
5
|
+
if (pageToken && pageEnvToken && pageToken === pageEnvToken) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default isAuthorizedForPage;
|
package/server/register.ts
CHANGED
|
@@ -16,6 +16,8 @@ export default async ({ strapi }: { strapi: Strapi }) => {
|
|
|
16
16
|
extensionService.use(pageType);
|
|
17
17
|
extensionService.use(getPageByPath(strapi));
|
|
18
18
|
extensionService.use(getPageInfoFromUID(strapi));
|
|
19
|
+
extensionService.shadowCRUD('api::page.page').disableActions(['find', 'findOne']);
|
|
19
20
|
|
|
20
21
|
await strapi.services?.['plugin::page-builder.builder']?.buildContentTypes();
|
|
22
|
+
await strapi.service('plugin::page-builder.private-content').enablePrivateContent();
|
|
21
23
|
};
|
package/server/routes/index.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
const routes = {
|
|
2
|
+
'private-content': {
|
|
3
|
+
type: 'content-api',
|
|
4
|
+
prefix: undefined,
|
|
5
|
+
routes: [
|
|
6
|
+
{
|
|
7
|
+
method: 'GET',
|
|
8
|
+
path: '/activate/:token',
|
|
9
|
+
handler: 'private-content.activateUser',
|
|
10
|
+
config: { policies: [], auth: false }
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
method: 'POST',
|
|
14
|
+
path: '/removeInactiveUsers',
|
|
15
|
+
handler: 'private-content.removeInactiveUsers'
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
},
|
|
2
19
|
'page-type': {
|
|
3
20
|
type: 'admin',
|
|
4
21
|
prefix: undefined,
|
|
@@ -11,10 +11,16 @@ import pageTypeEnd from '../schema/page-type-end.json';
|
|
|
11
11
|
import templateStart from '../schema/template-start.json';
|
|
12
12
|
import templateEnd from '../schema/template-end.json';
|
|
13
13
|
import platformStart from '../schema/platform-start.json';
|
|
14
|
+
import email from './private-content/components/email.json';
|
|
15
|
+
import platformEmail from './private-content/components/platform-email.json';
|
|
16
|
+
import adminEmail from './private-content/components/admin-email.json';
|
|
14
17
|
|
|
15
18
|
const UIDS: Common.UID.ContentType[] = [TEMPLATE_UID, PAGE_TYPE_UID, PLATFORM_UID, PAGE_UID];
|
|
16
19
|
|
|
17
20
|
export default {
|
|
21
|
+
async buildComponents() {
|
|
22
|
+
await this.createEmailComponents();
|
|
23
|
+
},
|
|
18
24
|
async buildContentTypes() {
|
|
19
25
|
this.listenToCreatedContentTypes();
|
|
20
26
|
|
|
@@ -29,7 +35,83 @@ export default {
|
|
|
29
35
|
}
|
|
30
36
|
});
|
|
31
37
|
},
|
|
32
|
-
|
|
38
|
+
async createEmailComponents() {
|
|
39
|
+
const foundEmailComponent = strapi.components['internal.email'];
|
|
40
|
+
const foundAdminEmail = strapi.components['internal.admin-email'];
|
|
41
|
+
const foundPlatformEmail = strapi.components['internal.platform-email'];
|
|
42
|
+
|
|
43
|
+
if (!foundAdminEmail && !foundEmailComponent && !foundPlatformEmail) {
|
|
44
|
+
try {
|
|
45
|
+
const res = await strapi.plugin('content-type-builder').services.components.createComponent({
|
|
46
|
+
component: {
|
|
47
|
+
category: 'internal',
|
|
48
|
+
displayName: platformEmail.info.displayName,
|
|
49
|
+
attributes: platformEmail.attributes
|
|
50
|
+
},
|
|
51
|
+
components: [
|
|
52
|
+
{
|
|
53
|
+
tmpUID: 'internal.email',
|
|
54
|
+
category: 'internal',
|
|
55
|
+
displayName: email.info.displayName,
|
|
56
|
+
attributes: email.attributes
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
tmpUID: 'internal.admin-email',
|
|
60
|
+
category: 'internal',
|
|
61
|
+
displayName: adminEmail.info.displayName,
|
|
62
|
+
attributes: adminEmail.attributes
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
return res;
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.log(error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
async createEmailComponent() {
|
|
73
|
+
try {
|
|
74
|
+
const res = await strapi.plugin('content-type-builder').services.components.createComponent({
|
|
75
|
+
component: {
|
|
76
|
+
category: 'internal',
|
|
77
|
+
displayName: email.info.displayName,
|
|
78
|
+
attributes: email.attributes
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return res;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.log(error);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
async createPlatformEmail() {
|
|
87
|
+
try {
|
|
88
|
+
const res = await strapi.plugin('content-type-builder').services.components.createComponent({
|
|
89
|
+
component: {
|
|
90
|
+
category: 'internal',
|
|
91
|
+
displayName: platformEmail.info.displayName,
|
|
92
|
+
attributes: platformEmail.attributes
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return res;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.log(error);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
async createAdminEmail() {
|
|
101
|
+
try {
|
|
102
|
+
const res = await strapi.plugin('content-type-builder').services.components.createComponent({
|
|
103
|
+
component: {
|
|
104
|
+
category: 'internal',
|
|
105
|
+
displayName: adminEmail.info.displayName,
|
|
106
|
+
attributes: adminEmail.attributes
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
console.log(res);
|
|
110
|
+
return res;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.log(error);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
33
115
|
async createContentTypes() {
|
|
34
116
|
const newContentTypes = UIDS.filter((c) => !Boolean(strapi.contentType(c)))
|
|
35
117
|
.map((c) => this.getContentType(c)?.create)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import * as AWS from '@aws-sdk/client-ses';
|
|
2
|
+
import { txtEmail } from './private-content/mail-template/txtMail.email.template.text';
|
|
3
|
+
import { USER_PERMISSION_USER_PLUGIN } from '../../shared/utils/constants';
|
|
4
|
+
|
|
5
|
+
interface SendOptions {
|
|
6
|
+
from: string;
|
|
7
|
+
to: string;
|
|
8
|
+
subject: string;
|
|
9
|
+
text: string;
|
|
10
|
+
variables?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
async sendMail(options: SendOptions) {
|
|
15
|
+
const { from, to, subject, text, variables } = options;
|
|
16
|
+
|
|
17
|
+
const emailData = txtEmail(text, variables);
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const client = new AWS.SES();
|
|
21
|
+
await client.sendEmail({
|
|
22
|
+
Source: from,
|
|
23
|
+
Destination: {
|
|
24
|
+
ToAddresses: [to]
|
|
25
|
+
},
|
|
26
|
+
Message: {
|
|
27
|
+
Subject: { Data: subject },
|
|
28
|
+
Body: {
|
|
29
|
+
Text: { Data: emailData }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error(error);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
async sendAdminMail(user) {
|
|
38
|
+
const foundUser = await strapi.entityService.findOne(USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
39
|
+
populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
|
|
40
|
+
});
|
|
41
|
+
await this.sendMail({
|
|
42
|
+
// @ts-ignore we all love strapi typings
|
|
43
|
+
from: foundUser.platform.platformEmails.adminEmail.fromEmail,
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
to: foundUser.platform.platformEmails.adminEmail.toEmail,
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
subject: foundUser.platform.platformEmails.adminEmail.subject,
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
text: foundUser.platform.platformEmails.adminEmail.message,
|
|
50
|
+
variables: {
|
|
51
|
+
firstName: user.firstName,
|
|
52
|
+
lastName: user.lastName
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
async sendConfirmationEmail(user) {
|
|
57
|
+
const foundUser = await strapi.entityService.findOne(USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
58
|
+
populate: { platform: { populate: { platformEmails: { populate: '*' } } } }
|
|
59
|
+
});
|
|
60
|
+
if (foundUser && foundUser.platform) {
|
|
61
|
+
const jwtService = strapi.plugin('users-permissions').service('jwt');
|
|
62
|
+
const confirmationToken = await jwtService.issue(
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
{ userId: user.id, platformId: foundUser.platform.id },
|
|
65
|
+
{ expiresIn: '1d' }
|
|
66
|
+
);
|
|
67
|
+
await strapi.entityService.update(USER_PERMISSION_USER_PLUGIN, user.id, {
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
data: { confirmationToken: confirmationToken }
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
const confirmEmailUrl = `${strapi.config.server.url}/api/page-builder/activate/${confirmationToken}`;
|
|
74
|
+
|
|
75
|
+
await this.sendMail({
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
from: foundUser.platform.platformEmails.accountCreatedMail.fromEmail,
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
to: foundUser.email,
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
subject: foundUser.platform.platformEmails.accountCreatedMail.subject,
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
text: foundUser.platform.platformEmails.accountCreatedMail.message,
|
|
84
|
+
variables: {
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
firstName: foundUser.firstName,
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
lastName: foundUser.lastName,
|
|
89
|
+
confirmEmailUrl
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
},
|
|
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
|
+
// @ts-ignore
|
|
104
|
+
data: { resetPasswordToken }
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
const searchParams = new URLSearchParams({ token: resetPasswordToken });
|
|
109
|
+
const resetPasswordUrl = `${user.platform.domain}/wachtwoord-resetten/?${searchParams.toString()}`;
|
|
110
|
+
|
|
111
|
+
await this.sendMail({
|
|
112
|
+
// @ts-ignore
|
|
113
|
+
from: user.platform.platformEmails.resetPasswordMail.fromEmail,
|
|
114
|
+
to: user.email,
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
subject: user.platform.platformEmails.resetPasswordMail.subject,
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
text: user.platform.platformEmails.resetPasswordMail.message,
|
|
119
|
+
variables: {
|
|
120
|
+
firstName: user?.firstName,
|
|
121
|
+
lastName: user?.lastName,
|
|
122
|
+
resetPasswordUrl
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
package/server/services/index.ts
CHANGED
|
@@ -4,6 +4,8 @@ import pageType from './page-type';
|
|
|
4
4
|
import collectionTypes from './collection-types';
|
|
5
5
|
import template from './template';
|
|
6
6
|
import platform from './platform';
|
|
7
|
+
import email from './email';
|
|
8
|
+
import privateContent from './private-content';
|
|
7
9
|
|
|
8
10
|
export default {
|
|
9
11
|
page,
|
|
@@ -11,5 +13,7 @@ export default {
|
|
|
11
13
|
'page-type': pageType,
|
|
12
14
|
'collection-types': collectionTypes,
|
|
13
15
|
template,
|
|
14
|
-
platform
|
|
16
|
+
platform,
|
|
17
|
+
email,
|
|
18
|
+
'private-content': privateContent
|
|
15
19
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"collectionName": "components_internal_admin_emails",
|
|
3
|
+
"info": {
|
|
4
|
+
"displayName": "AdminEmail",
|
|
5
|
+
"description": ""
|
|
6
|
+
},
|
|
7
|
+
"options": {},
|
|
8
|
+
"attributes": {
|
|
9
|
+
"toEmail": {
|
|
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,13 @@
|
|
|
1
|
+
import { contentTypes as contentTypesUtils } from '@strapi/utils';
|
|
2
|
+
export const { UPDATED_BY_ATTRIBUTE, CREATED_BY_ATTRIBUTE } = contentTypesUtils.constants;
|
|
3
|
+
|
|
4
|
+
export const USER_MODEL = 'plugin::users-permissions.user';
|
|
5
|
+
export const USER_CONTENT_MANAGER = 'plugin::users-permissions.contentmanageruser';
|
|
6
|
+
export const USER_ROLE = 'plugin::users-permissions.role';
|
|
7
|
+
export const CONTENT_ENTITY_MANAGER = 'plugin::content-manager.entity-manager';
|
|
8
|
+
export const ACTIONS = {
|
|
9
|
+
read: 'plugin::content-manager.explorer.read',
|
|
10
|
+
create: 'plugin::content-manager.explorer.create',
|
|
11
|
+
edit: 'plugin::content-manager.explorer.update',
|
|
12
|
+
delete: 'plugin::content-manager.explorer.delete'
|
|
13
|
+
};
|