@webbio/strapi-plugin-page-builder 0.9.13-authentication → 0.9.15-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 +1 -1
- package/dist/server/content-types/category/category.js +0 -0
- package/dist/server/content-types/category/category.json +27 -0
- package/dist/server/content-types/page-version/schema.json +16 -0
- package/dist/server/controllers/page-version.js +7 -0
- package/dist/server/graphql/page-by-path.js +1 -1
- package/dist/server/graphql/page-by-slug.js +89 -0
- package/dist/server/middlewares/private-content.js +13 -0
- package/dist/server/routes/page-version.js +7 -0
- package/dist/server/services/authentication.js +186 -0
- package/dist/server/services/page-version.js +7 -0
- package/dist/server/services/private-content/acceptedMail/acceptMail.email.template.text.js +12 -0
- package/dist/server/services/private-content/acceptedMail/acceptMail.interface.js +2 -0
- package/dist/server/services/private-content/graphql/resolvers/find.js +0 -0
- package/dist/server/services/private-content/graphql/resolvers/findAll.js +0 -0
- package/dist/server/services/private-content/graphql/resolvers/findOnePage.js +1 -1
- package/dist/server/services/private-content/graphql/resolvers/findPage.js +5 -4
- package/dist/server/services/private-content/graphql/resolvers/forgot-password.js +7 -2
- package/dist/server/services/private-content/graphql/resolvers/login.js +8 -3
- package/dist/server/services/private-content/graphql/resolvers/register.js +14 -5
- package/dist/server/services/private-content/graphql/types/index.js +3 -4
- package/dist/server/services/private-content/schemas/index.js +3 -3
- package/dist/server/utils/graphql.js +100 -0
- package/dist/server/utils/paginationValidation.js +31 -0
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/server/graphql/page-by-path.ts +1 -1
- package/server/services/private-content/graphql/resolvers/findOnePage.ts +1 -1
- package/server/services/private-content/graphql/resolvers/findPage.ts +4 -4
- package/server/services/private-content/graphql/resolvers/forgot-password.ts +10 -2
- package/server/services/private-content/graphql/resolvers/login.ts +8 -3
- package/server/services/private-content/graphql/resolvers/register.ts +17 -5
- package/server/services/private-content/graphql/types/index.ts +3 -4
- package/server/services/private-content/schemas/index.ts +3 -3
package/dist/package.json
CHANGED
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
},
|
|
12
|
+
"pluginOptions": {
|
|
13
|
+
"i18n": {
|
|
14
|
+
"localized": true
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"attributes": {
|
|
18
|
+
"title": {
|
|
19
|
+
"pluginOptions": {
|
|
20
|
+
"i18n": {
|
|
21
|
+
"localized": true
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"type": "string"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kind": "collectionType",
|
|
3
|
+
"collectionName": "page_versions",
|
|
4
|
+
"info": {
|
|
5
|
+
"singularName": "page-version",
|
|
6
|
+
"pluralName": "page-versions",
|
|
7
|
+
"displayName": "page-version"
|
|
8
|
+
},
|
|
9
|
+
"options": {
|
|
10
|
+
"draftAndPublish": false,
|
|
11
|
+
"comment": ""
|
|
12
|
+
},
|
|
13
|
+
"attributes": {
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -63,7 +63,7 @@ const getPageByPath = (strapi) => {
|
|
|
63
63
|
};
|
|
64
64
|
const results = await getPage();
|
|
65
65
|
if (((_a = Object.values(results)) === null || _a === void 0 ? void 0 : _a.filter(Boolean).length) > 0) {
|
|
66
|
-
if (!((_b = results === null || results === void 0 ? void 0 : results.platform) === null || _b === void 0 ? void 0 : _b.isPrivate) && !results.isPrivate) {
|
|
66
|
+
if (!((_b = results === null || results === void 0 ? void 0 : results.platform) === null || _b === void 0 ? void 0 : _b.isPrivate) && !(results === null || results === void 0 ? void 0 : results.isPrivate)) {
|
|
67
67
|
return results;
|
|
68
68
|
}
|
|
69
69
|
if ((((_c = results === null || results === void 0 ? void 0 : results.platform) === null || _c === void 0 ? void 0 : _c.isPrivate) === true && ctx.koaContext.req.headers.authorization) ||
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const filter_underscore_arguments_1 = require("../utils/filter-underscore-arguments");
|
|
4
|
+
const constants_1 = require("../../shared/utils/constants");
|
|
5
|
+
const getPageBySlug = (strapi) => {
|
|
6
|
+
const typeDefs = () => {
|
|
7
|
+
return `
|
|
8
|
+
extend type Page {
|
|
9
|
+
collectionType: GenericMorph
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type Query {
|
|
13
|
+
getPageBySlug(path: String, _domain: String, _locale: String, _publicationState: PublicationState): PageEntity
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
`;
|
|
17
|
+
};
|
|
18
|
+
const resolvers = (strapi) => {
|
|
19
|
+
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
20
|
+
return {
|
|
21
|
+
Query: {
|
|
22
|
+
getPageBySlug: {
|
|
23
|
+
resolve: async (_parent, args, ctx) => {
|
|
24
|
+
var _a;
|
|
25
|
+
try {
|
|
26
|
+
const filteredArgs = {
|
|
27
|
+
...(0, filter_underscore_arguments_1.filterUnderscoreArguments)(args),
|
|
28
|
+
platform: { domain: args._domain }
|
|
29
|
+
};
|
|
30
|
+
const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
|
|
31
|
+
const getPage = async () => {
|
|
32
|
+
var _a, _b, _c;
|
|
33
|
+
const transformedArgs = transformArgs(filteredArgs, {
|
|
34
|
+
contentType: strapi.contentTypes[constants_1.PAGE_UID],
|
|
35
|
+
usePagination: false
|
|
36
|
+
});
|
|
37
|
+
const results = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_UID, {
|
|
38
|
+
filters: filteredArgs,
|
|
39
|
+
locale: args._locale,
|
|
40
|
+
publicationState: args._publicationState,
|
|
41
|
+
populate: '*'
|
|
42
|
+
}));
|
|
43
|
+
const entityResponse = toEntityResponse((results === null || results === void 0 ? void 0 : results[0]) || {}, {
|
|
44
|
+
args: transformedArgs,
|
|
45
|
+
resourceUID: constants_1.PAGE_UID
|
|
46
|
+
});
|
|
47
|
+
if (!(entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) || Object.keys(entityResponse.value).length === 0) {
|
|
48
|
+
throw new Error(ctx.koaContext.response.message);
|
|
49
|
+
}
|
|
50
|
+
const collectionTypeDataFilter = (_c = (_b = entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) === null || _b === void 0 ? void 0 : _b.collectionTypeData) === null || _c === void 0 ? void 0 : _c.filter(Boolean);
|
|
51
|
+
const collectionType = collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter === null || collectionTypeDataFilter === void 0 ? void 0 : collectionTypeDataFilter[0] : null;
|
|
52
|
+
const addedAttributes = {
|
|
53
|
+
collectionType: collectionType
|
|
54
|
+
};
|
|
55
|
+
const result = {
|
|
56
|
+
...entityResponse.value,
|
|
57
|
+
...addedAttributes
|
|
58
|
+
};
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
const results = await getPage();
|
|
62
|
+
if (((_a = Object.values(results)) === null || _a === void 0 ? void 0 : _a.filter(Boolean).length) > 0) {
|
|
63
|
+
return results;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new Error(ctx.koaContext.response.message);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.log('Error in getPageBySlug:', error);
|
|
71
|
+
throw new Error(ctx.koaContext.response.message);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const resolversConfig = {
|
|
79
|
+
'Query.getPageBySlug': {
|
|
80
|
+
auth: false
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
typeDefs: typeDefs(),
|
|
85
|
+
resolvers: resolvers(strapi),
|
|
86
|
+
resolversConfig
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
exports.default = getPageBySlug;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `private-content` middleware
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = (config, { strapi }) => {
|
|
7
|
+
// Add your own logic here.
|
|
8
|
+
return async (ctx, next) => {
|
|
9
|
+
strapi.log.info('[PRIVATE CONTENT] Before');
|
|
10
|
+
await next();
|
|
11
|
+
strapi.log.info('[PRIVATE CONTENT] After');
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@strapi/utils");
|
|
4
|
+
const utils_2 = require("@strapi/utils");
|
|
5
|
+
const { ApplicationError } = utils_2.errors;
|
|
6
|
+
const registerSchema = utils_1.yup.object({
|
|
7
|
+
email: utils_1.yup.string().email().required(),
|
|
8
|
+
password: utils_1.yup.string().required(),
|
|
9
|
+
platformId: utils_1.yup.number().required()
|
|
10
|
+
});
|
|
11
|
+
exports.default = {
|
|
12
|
+
registerAuthentication() {
|
|
13
|
+
this.extendUser();
|
|
14
|
+
this.extendGraphQL();
|
|
15
|
+
},
|
|
16
|
+
extendUser() {
|
|
17
|
+
const user = strapi.contentType('plugin::users-permissions.user');
|
|
18
|
+
user.attributes = {
|
|
19
|
+
...user.attributes,
|
|
20
|
+
firstName: {
|
|
21
|
+
type: 'string'
|
|
22
|
+
},
|
|
23
|
+
lastName: {
|
|
24
|
+
type: 'string'
|
|
25
|
+
},
|
|
26
|
+
company: {
|
|
27
|
+
type: 'string'
|
|
28
|
+
},
|
|
29
|
+
jobTitle: {
|
|
30
|
+
type: 'string'
|
|
31
|
+
},
|
|
32
|
+
address: {
|
|
33
|
+
type: 'string'
|
|
34
|
+
},
|
|
35
|
+
postalCode: {
|
|
36
|
+
type: 'string'
|
|
37
|
+
},
|
|
38
|
+
city: {
|
|
39
|
+
type: 'string'
|
|
40
|
+
},
|
|
41
|
+
country: {
|
|
42
|
+
type: 'string'
|
|
43
|
+
},
|
|
44
|
+
phone: {
|
|
45
|
+
type: 'string'
|
|
46
|
+
},
|
|
47
|
+
platform: {
|
|
48
|
+
type: 'relation',
|
|
49
|
+
relation: 'oneToOne',
|
|
50
|
+
target: 'api::platform.platform'
|
|
51
|
+
},
|
|
52
|
+
categories: {
|
|
53
|
+
type: 'relation',
|
|
54
|
+
relation: 'oneToMany',
|
|
55
|
+
target: 'api::category.category'
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
delete user.attributes.username;
|
|
59
|
+
},
|
|
60
|
+
extendGraphQL() {
|
|
61
|
+
const extensionService = strapi.plugin('graphql').service('extension');
|
|
62
|
+
const extension = () => ({
|
|
63
|
+
typeDefs: `
|
|
64
|
+
input LoginInput {
|
|
65
|
+
email: String!
|
|
66
|
+
password: String!
|
|
67
|
+
platformId: ID!
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
input RegisterInput {
|
|
71
|
+
email: String!
|
|
72
|
+
password: String!
|
|
73
|
+
firstName: String
|
|
74
|
+
lastName: String
|
|
75
|
+
company: String
|
|
76
|
+
jobTitle: String
|
|
77
|
+
address: String
|
|
78
|
+
postalCode: String
|
|
79
|
+
city: String
|
|
80
|
+
country: String
|
|
81
|
+
phone: String
|
|
82
|
+
subscribeToNewsletter: Boolean
|
|
83
|
+
categories: [ID]
|
|
84
|
+
platformId: ID!
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
type LoginResponse {
|
|
88
|
+
jwt: String
|
|
89
|
+
user: User
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type RegisterResponse {
|
|
93
|
+
user: User
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
type ForgotPasswordResponse {
|
|
97
|
+
ok: Boolean!
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
type User {
|
|
101
|
+
id: ID!
|
|
102
|
+
email: String!
|
|
103
|
+
confirmed: Boolean
|
|
104
|
+
blocked: Boolean
|
|
105
|
+
activated: Boolean
|
|
106
|
+
platformId: ID!
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type Mutation {
|
|
110
|
+
platformLogin(input: LoginInput!): LoginResponse
|
|
111
|
+
platformRegister(input: RegisterInput!): RegisterResponse
|
|
112
|
+
platformForgotPassword(email: String!): ForgotPasswordResponse
|
|
113
|
+
}
|
|
114
|
+
`,
|
|
115
|
+
resolversConfig: {
|
|
116
|
+
'Mutation.platformLogin': {
|
|
117
|
+
auth: false
|
|
118
|
+
},
|
|
119
|
+
'Mutation.platformRegister': {
|
|
120
|
+
auth: false
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
resolvers: {
|
|
124
|
+
Mutation: {
|
|
125
|
+
platformLogin: {
|
|
126
|
+
resolve() {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
platformRegister: {
|
|
131
|
+
async resolve(parent, args) {
|
|
132
|
+
const pluginStore = strapi.store({ type: 'plugin', name: 'users-permissions' });
|
|
133
|
+
const settings = await pluginStore.get({ key: 'advanced' });
|
|
134
|
+
if (!settings.allow_register) {
|
|
135
|
+
throw new ApplicationError('Register action is currently disabled');
|
|
136
|
+
}
|
|
137
|
+
await (0, utils_1.validateYupSchema)(args.input, registerSchema);
|
|
138
|
+
const { email, platformId } = args.input;
|
|
139
|
+
const role = await strapi
|
|
140
|
+
.query('plugin::users-permissions.role')
|
|
141
|
+
.findOne({ where: { type: settings.default_role } });
|
|
142
|
+
if (!role) {
|
|
143
|
+
throw new ApplicationError('Impossible to find the default role');
|
|
144
|
+
}
|
|
145
|
+
const conflictingUserCount = await strapi.query('plugin::users-permissions.user').count({
|
|
146
|
+
where: {
|
|
147
|
+
email,
|
|
148
|
+
platform: {
|
|
149
|
+
id: platformId
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (conflictingUserCount > 0) {
|
|
154
|
+
throw new ApplicationError('Email is already taken');
|
|
155
|
+
}
|
|
156
|
+
const userData = {
|
|
157
|
+
...args.input,
|
|
158
|
+
role: role.id,
|
|
159
|
+
email: email.toLowerCase(),
|
|
160
|
+
confirmed: false,
|
|
161
|
+
provider: 'local',
|
|
162
|
+
categories: args.input.categories,
|
|
163
|
+
platform: {
|
|
164
|
+
set: platformId
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const createdUser = await strapi.query('plugin::users-permissions.user').create({
|
|
168
|
+
data: userData,
|
|
169
|
+
populate: ['role', 'platform', 'categories']
|
|
170
|
+
});
|
|
171
|
+
const userSchema = strapi.getModel('plugin::users-permissions.user');
|
|
172
|
+
const sanitizedUser = await utils_2.sanitize.contentAPI.output(createdUser, userSchema, {
|
|
173
|
+
auth: false
|
|
174
|
+
});
|
|
175
|
+
return {
|
|
176
|
+
user: sanitizedUser
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
extensionService.use(extension);
|
|
184
|
+
},
|
|
185
|
+
async register(ctx) { }
|
|
186
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.acceptMailTxtEmail = void 0;
|
|
7
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
+
const acceptMailTxtEmail = (acceptMailData) => {
|
|
9
|
+
const template = handlebars_1.default.compile(acceptMailData.text);
|
|
10
|
+
return template(acceptMailData);
|
|
11
|
+
};
|
|
12
|
+
exports.acceptMailTxtEmail = acceptMailTxtEmail;
|
|
File without changes
|
|
File without changes
|
|
@@ -16,7 +16,7 @@ exports.page = {
|
|
|
16
16
|
const sanitizedQuery = await utils_1.sanitize.contentAPI.query(populatedArgs, strapi.contentType(constants_1.PAGE_UID));
|
|
17
17
|
const value = await strapi.entityService.findOne(uid, args.id, (0, fp_1.omit)('id', sanitizedQuery));
|
|
18
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) {
|
|
19
|
+
if (!((_a = value === null || value === void 0 ? void 0 : value.platform) === null || _a === void 0 ? void 0 : _a.isPrivate) && !(value === null || value === void 0 ? void 0 : value.isPrivate)) {
|
|
20
20
|
return toEntityResponse(value, { args: transformedArgs, resourceUID: uid });
|
|
21
21
|
}
|
|
22
22
|
if (
|
|
@@ -21,15 +21,16 @@ exports.pages = {
|
|
|
21
21
|
if (decodedToken) {
|
|
22
22
|
// @ts-ignore
|
|
23
23
|
const filteredItems = value.filter((item) => {
|
|
24
|
+
var _a, _b;
|
|
24
25
|
// @ts-ignore
|
|
25
|
-
if (item.platform.isPrivate === true && user.platform.id === item.platform.id) {
|
|
26
|
+
if (((_a = item.platform) === null || _a === void 0 ? void 0 : _a.isPrivate) === true && user.platform.id === item.platform.id) {
|
|
26
27
|
return item;
|
|
27
28
|
}
|
|
28
|
-
if (item.isPrivate === true && user.platform.id === item.platform.id) {
|
|
29
|
+
if ((item === null || item === void 0 ? void 0 : item.isPrivate) === true && user.platform.id === item.platform.id) {
|
|
29
30
|
return item;
|
|
30
31
|
}
|
|
31
32
|
// @ts-ignore
|
|
32
|
-
if (item.platform.isPrivate !== true && item.isPrivate !== true) {
|
|
33
|
+
if (((_b = item.platform) === null || _b === void 0 ? void 0 : _b.isPrivate) !== true && (item === null || item === void 0 ? void 0 : item.isPrivate) !== true) {
|
|
33
34
|
return item;
|
|
34
35
|
}
|
|
35
36
|
});
|
|
@@ -37,7 +38,7 @@ exports.pages = {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
// @ts-ignore
|
|
40
|
-
const filteredItems = value.filter((item) => item.platform.isPrivate !== true && item.isPrivate !== true);
|
|
41
|
+
const filteredItems = value.filter((item) => { var _a; return ((_a = item.platform) === null || _a === void 0 ? void 0 : _a.isPrivate) !== true && (item === null || item === void 0 ? void 0 : item.isPrivate) !== true; });
|
|
41
42
|
return toEntityResponseCollection(filteredItems, { args: transformedArgs, resourceUID: uid });
|
|
42
43
|
}
|
|
43
44
|
};
|
|
@@ -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,
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
|
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,22 @@ 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,
|
|
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
|
+
console.log(platform);
|
|
21
|
+
if (!platform) {
|
|
22
|
+
throw new NotFoundError('Platform not found');
|
|
23
|
+
}
|
|
15
24
|
const role = await strapi
|
|
16
25
|
.query('plugin::users-permissions.role')
|
|
17
26
|
.findOne({ where: { type: settings.default_role } });
|
|
@@ -22,11 +31,11 @@ exports.platformRegister = {
|
|
|
22
31
|
where: {
|
|
23
32
|
$and: [
|
|
24
33
|
{
|
|
25
|
-
email
|
|
34
|
+
email: email.toLowerCase()
|
|
26
35
|
},
|
|
27
36
|
{
|
|
28
37
|
platform: {
|
|
29
|
-
id:
|
|
38
|
+
id: platform.id
|
|
30
39
|
}
|
|
31
40
|
}
|
|
32
41
|
]
|
|
@@ -39,7 +48,7 @@ exports.platformRegister = {
|
|
|
39
48
|
...args.input,
|
|
40
49
|
role: role.id,
|
|
41
50
|
categories: args.input.categories,
|
|
42
|
-
platform:
|
|
51
|
+
platform: platform.id,
|
|
43
52
|
email: email.toLowerCase(),
|
|
44
53
|
provider: 'local',
|
|
45
54
|
confirmed: false,
|
|
@@ -5,13 +5,13 @@ exports.LoginInput = `
|
|
|
5
5
|
input LoginInput {
|
|
6
6
|
email: String!
|
|
7
7
|
password: String!
|
|
8
|
-
|
|
8
|
+
domain: String!
|
|
9
9
|
}
|
|
10
10
|
`;
|
|
11
11
|
exports.ForgotPasswordInput = `
|
|
12
12
|
input ForgotPasswordInput {
|
|
13
13
|
email: String!
|
|
14
|
-
|
|
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
|
-
|
|
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 = `
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(),
|