@webbio/strapi-plugin-page-builder 0.9.7-platform → 0.9.8-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/admin/src/components/PlatformFilteredSelectField/index.tsx +35 -2
- package/dist/package.json +9 -3
- package/dist/server/bootstrap.js +31 -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 +9 -3
- package/server/bootstrap.ts +39 -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,40 @@
|
|
|
1
|
+
import { omit } from 'lodash/fp';
|
|
2
|
+
import { sanitize } from '@strapi/utils';
|
|
3
|
+
import { PAGE_UID } from '../../../../../shared/utils/constants';
|
|
4
|
+
import { ForbiddenError as ApolloForbiddenError } from 'apollo-server-koa';
|
|
5
|
+
|
|
6
|
+
export const page = {
|
|
7
|
+
async resolve(parent, args, ctx) {
|
|
8
|
+
const uid = PAGE_UID;
|
|
9
|
+
const { toEntityResponse } = 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(PAGE_UID));
|
|
13
|
+
const sanitizedQuery = await sanitize.contentAPI.query(populatedArgs, strapi.contentType(PAGE_UID));
|
|
14
|
+
const value = await strapi.entityService!.findOne(uid, args.id, omit('id', sanitizedQuery));
|
|
15
|
+
// @ts-ignore Strapi types are the best
|
|
16
|
+
if (!value?.platform?.isPrivate && !value.isPrivate) {
|
|
17
|
+
return toEntityResponse(value, { args: transformedArgs, resourceUID: uid });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (
|
|
21
|
+
// @ts-ignore Strapi types are the best
|
|
22
|
+
(value?.platform?.isPrivate === true && ctx.koaContext.req.headers.authorization) ||
|
|
23
|
+
(value?.isPrivate === true && ctx.koaContext.req.headers.authorization)
|
|
24
|
+
) {
|
|
25
|
+
const auth = ctx.koaContext.req.headers.authorization;
|
|
26
|
+
const token = auth.split(' ');
|
|
27
|
+
|
|
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 (user?.platform?.id === value?.platform?.id) {
|
|
34
|
+
return toEntityResponse(value, { args: transformedArgs, resourceUID: uid });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return new ApolloForbiddenError('Forbidden access');
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { sanitize } from '@strapi/utils';
|
|
2
|
+
import { PAGE_UID } from '../../../../../shared/utils/constants';
|
|
3
|
+
|
|
4
|
+
export const pages = {
|
|
5
|
+
async resolve(parent, args, ctx) {
|
|
6
|
+
const uid = PAGE_UID;
|
|
7
|
+
const { toEntityResponseCollection } = strapi.plugin('graphql').service('format').returnTypes;
|
|
8
|
+
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
9
|
+
const populatedArgs = { ...args, populate: { platform: true } };
|
|
10
|
+
const transformedArgs = transformArgs(populatedArgs, strapi.contentType(PAGE_UID));
|
|
11
|
+
const sanitizedQuery = await sanitize.contentAPI.query(populatedArgs, strapi.contentType(PAGE_UID));
|
|
12
|
+
const value = await strapi.entityService!.findMany(uid, sanitizedQuery);
|
|
13
|
+
|
|
14
|
+
const user = ctx.state.user;
|
|
15
|
+
|
|
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
|
+
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
const filteredItems = value.filter((item) => item.platform.isPrivate !== true && item.isPrivate !== true);
|
|
42
|
+
|
|
43
|
+
return toEntityResponseCollection(filteredItems, { args: transformedArgs, resourceUID: uid });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { errors } from '@strapi/utils';
|
|
2
|
+
import { USER_MODEL } from '../../constants';
|
|
3
|
+
import { validateForgotPasswordSchema } from '../../schemas';
|
|
4
|
+
const { UnauthorizedError } = errors;
|
|
5
|
+
|
|
6
|
+
export const platformForgotPassword = {
|
|
7
|
+
async resolve(parent, args, context) {
|
|
8
|
+
await validateForgotPasswordSchema(args.input);
|
|
9
|
+
|
|
10
|
+
const { email, platformId } = args.input;
|
|
11
|
+
|
|
12
|
+
const user = await strapi.query(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,51 @@
|
|
|
1
|
+
import { errors, sanitize } from '@strapi/utils';
|
|
2
|
+
import { USER_MODEL } from '../../constants';
|
|
3
|
+
import { validateLoginSchema } from '../../schemas';
|
|
4
|
+
const { UnauthorizedError } = errors;
|
|
5
|
+
|
|
6
|
+
export const platformLogin = {
|
|
7
|
+
async resolve(parent, args, context) {
|
|
8
|
+
await validateLoginSchema(args.input);
|
|
9
|
+
|
|
10
|
+
const { email, password, platformId } = args.input;
|
|
11
|
+
|
|
12
|
+
const user = await strapi.query(USER_MODEL).findOne({
|
|
13
|
+
where: {
|
|
14
|
+
email: email.toLowerCase(),
|
|
15
|
+
platform: {
|
|
16
|
+
id: platformId
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (user == null) {
|
|
22
|
+
throw new UnauthorizedError('Invalid email or password');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const isPasswordValid = await strapi
|
|
26
|
+
.service('plugin::users-permissions.user')
|
|
27
|
+
.validatePassword(password, user.password);
|
|
28
|
+
|
|
29
|
+
if (isPasswordValid === false) {
|
|
30
|
+
throw new UnauthorizedError('Invalid email or password');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (user.confirmed === false) {
|
|
34
|
+
throw new UnauthorizedError('Email is not confirmed');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (user.activateUser === false) {
|
|
38
|
+
throw new UnauthorizedError('Account is not activated');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const sanitizedUser = sanitize.contentAPI.output(user, strapi.getModel(USER_MODEL), {
|
|
42
|
+
auth: false
|
|
43
|
+
});
|
|
44
|
+
const jwt = await strapi.service('plugin::users-permissions.jwt').issue({ id: user.id, platformId: platformId });
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
user: sanitizedUser,
|
|
48
|
+
jwt
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { sanitize } from '@strapi/utils';
|
|
2
|
+
import { errors } from '@strapi/utils';
|
|
3
|
+
import { USER_MODEL } from '../../constants';
|
|
4
|
+
import { validateRegisterSchema } from '../../schemas';
|
|
5
|
+
const { ApplicationError } = errors;
|
|
6
|
+
|
|
7
|
+
export const platformRegister = {
|
|
8
|
+
async resolve(parent, args, context) {
|
|
9
|
+
const pluginStore = await strapi.store({ type: 'plugin', name: 'users-permissions' });
|
|
10
|
+
const settings: any = await pluginStore.get({ key: 'advanced' });
|
|
11
|
+
|
|
12
|
+
await validateRegisterSchema(args.input);
|
|
13
|
+
|
|
14
|
+
const { email, platformId } = args.input;
|
|
15
|
+
|
|
16
|
+
const role = await strapi
|
|
17
|
+
.query('plugin::users-permissions.role')
|
|
18
|
+
.findOne({ where: { type: settings.default_role } });
|
|
19
|
+
|
|
20
|
+
if (!role) {
|
|
21
|
+
throw new ApplicationError('Impossible to find the default role');
|
|
22
|
+
}
|
|
23
|
+
const conflictingUserCount = await strapi.query(USER_MODEL).count({
|
|
24
|
+
where: {
|
|
25
|
+
$and: [
|
|
26
|
+
{
|
|
27
|
+
email
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
platform: {
|
|
31
|
+
id: platformId
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (conflictingUserCount > 0) {
|
|
39
|
+
throw new ApplicationError('Email is already taken');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const userData = {
|
|
43
|
+
...args.input,
|
|
44
|
+
role: role.id,
|
|
45
|
+
categories: args.input.categories,
|
|
46
|
+
platform: platformId,
|
|
47
|
+
email: email.toLowerCase(),
|
|
48
|
+
provider: 'local',
|
|
49
|
+
confirmed: false,
|
|
50
|
+
activateUser: false
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const createdUser = await strapi.entityService.create(USER_MODEL, {
|
|
54
|
+
data: userData
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const userModel = strapi.getModel(USER_MODEL);
|
|
58
|
+
const sanitizedUser = sanitize.contentAPI.output(createdUser, userModel, {
|
|
59
|
+
auth: false
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
await strapi.service('plugin::page-builder.email').sendConfirmationEmail(createdUser);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
user: sanitizedUser
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { sanitize } from '@strapi/utils';
|
|
2
|
+
import { USER_MODEL } from '../../constants';
|
|
3
|
+
import { validateResetPasswordSchema } from '../../schemas';
|
|
4
|
+
|
|
5
|
+
export const platformResetPassword = {
|
|
6
|
+
async resolve(parent, args, context) {
|
|
7
|
+
await validateResetPasswordSchema(args.input);
|
|
8
|
+
|
|
9
|
+
const { password, resetPasswordToken } = args.input;
|
|
10
|
+
|
|
11
|
+
const jwtService = strapi.plugin('users-permissions').service('jwt');
|
|
12
|
+
const decodedToken = await jwtService.verify(resetPasswordToken);
|
|
13
|
+
|
|
14
|
+
if (decodedToken) {
|
|
15
|
+
const user = await strapi.query(USER_MODEL).findOne({
|
|
16
|
+
where: {
|
|
17
|
+
id: decodedToken.userId,
|
|
18
|
+
resetPasswordToken: resetPasswordToken
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
if (user && user.resetPasswordToken && user.resetPasswordToken === resetPasswordToken) {
|
|
22
|
+
if (password) {
|
|
23
|
+
await strapi.entityService.update(USER_MODEL, user.id, {
|
|
24
|
+
data: {
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
password: password,
|
|
27
|
+
resetPasswordToken: null
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const userModel = strapi.getModel(USER_MODEL);
|
|
33
|
+
const sanitizedUser = sanitize.contentAPI.output(user, userModel, {
|
|
34
|
+
auth: false
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
user: sanitizedUser
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw new Error('Time of token has expired request a new password change');
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export const LoginInput = `
|
|
2
|
+
input LoginInput {
|
|
3
|
+
email: String!
|
|
4
|
+
password: String!
|
|
5
|
+
platformId: ID!
|
|
6
|
+
}
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
export const ForgotPasswordInput = `
|
|
10
|
+
input ForgotPasswordInput {
|
|
11
|
+
email: String!
|
|
12
|
+
platformId: ID!
|
|
13
|
+
}`;
|
|
14
|
+
|
|
15
|
+
export const RegisterInput = `
|
|
16
|
+
input RegisterInput {
|
|
17
|
+
email: String!
|
|
18
|
+
password: String!
|
|
19
|
+
firstName: String
|
|
20
|
+
lastName: String
|
|
21
|
+
company: String
|
|
22
|
+
jobTitle: String
|
|
23
|
+
address: String
|
|
24
|
+
postalCode: String
|
|
25
|
+
city: String
|
|
26
|
+
country: String
|
|
27
|
+
phone: String
|
|
28
|
+
subscribeToNewsletter: Boolean
|
|
29
|
+
categories: [ID]
|
|
30
|
+
platformId: ID!
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
export const LoginResponse = `
|
|
35
|
+
type LoginResponse {
|
|
36
|
+
jwt: String
|
|
37
|
+
user: User
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
export const RegisterResponse = `
|
|
42
|
+
type RegisterResponse {
|
|
43
|
+
user: User
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
export const ForgotPasswordResponse = `
|
|
48
|
+
type ForgotPasswordResponse {
|
|
49
|
+
message: String
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
export const User = `
|
|
54
|
+
type User {
|
|
55
|
+
id: ID!
|
|
56
|
+
email: String!
|
|
57
|
+
confirmed: Boolean
|
|
58
|
+
blocked: Boolean
|
|
59
|
+
activated: Boolean
|
|
60
|
+
platformId: ID!
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
export const ResetPassword = `
|
|
65
|
+
type ResetPassword {
|
|
66
|
+
jwt: String
|
|
67
|
+
email: String
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
export const ResetPasswordInput = `
|
|
71
|
+
input ResetPasswordInput {
|
|
72
|
+
password: String!
|
|
73
|
+
passwordConfirmation: String!
|
|
74
|
+
resetPasswordToken: String!
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
export const ResetPasswordResponse = `
|
|
79
|
+
type ResetPasswordResponse {
|
|
80
|
+
user: User
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
export const Mutations = `
|
|
85
|
+
type Mutation {
|
|
86
|
+
platformLogin(input: LoginInput!): LoginResponse
|
|
87
|
+
platformRegister(input: RegisterInput!): RegisterResponse
|
|
88
|
+
platformForgotPassword(input: ForgotPasswordInput!): ForgotPasswordResponse
|
|
89
|
+
platformResetPassword(input: ResetPasswordInput!): ResetPasswordResponse
|
|
90
|
+
}
|
|
91
|
+
`;
|
|
92
|
+
|
|
93
|
+
export const Queries = `
|
|
94
|
+
type Query {
|
|
95
|
+
page(id: ID, locale: I18NLocaleCode): PageEntityResponse
|
|
96
|
+
pages(filters: PageFiltersInput pagination: PaginationArg = {} sort: [String] = [] publicationState: PublicationState = LIVE locale: I18NLocaleCode): PageEntityResponseCollection
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { getConfig } from '../../utils/strapi';
|
|
2
|
+
import { extendControllers, extendUser } from './user';
|
|
3
|
+
import { extendGraphQL } from './graphql';
|
|
4
|
+
import { extendPlatform } from './platform';
|
|
5
|
+
import { extendPage } from './page';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
async enablePrivateContent() {
|
|
9
|
+
if (this.isPrivateContentEnabled) {
|
|
10
|
+
await strapi.services?.['plugin::page-builder.builder']?.buildComponents();
|
|
11
|
+
extendUser();
|
|
12
|
+
extendControllers();
|
|
13
|
+
extendGraphQL();
|
|
14
|
+
extendPlatform();
|
|
15
|
+
extendPage();
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
isPrivateContentEnabled(): boolean {
|
|
19
|
+
const pageBuilderConfig = getConfig();
|
|
20
|
+
return pageBuilderConfig?.privateContent === true;
|
|
21
|
+
},
|
|
22
|
+
async activateUser(token: string) {
|
|
23
|
+
const jwtService = strapi.plugin('users-permissions').service('jwt');
|
|
24
|
+
const decodedToken = await jwtService.verify(token);
|
|
25
|
+
|
|
26
|
+
if (decodedToken) {
|
|
27
|
+
const user = await strapi.query('plugin::users-permissions.user').findOne({
|
|
28
|
+
where: {
|
|
29
|
+
id: decodedToken.userId,
|
|
30
|
+
platform: {
|
|
31
|
+
id: decodedToken.platformId
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (!user.confirmed && user.confirmationToken && user.confirmationToken === token) {
|
|
36
|
+
await strapi.entityService.update('plugin::users-permissions.user', user.id, {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
data: { confirmed: true, confirmationToken: null }
|
|
39
|
+
});
|
|
40
|
+
await strapi.service('plugin::page-builder.email').sendAdminMail(user);
|
|
41
|
+
|
|
42
|
+
return ' User has been created';
|
|
43
|
+
}
|
|
44
|
+
throw new Error('User already activated');
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
async removeInactiveUsers() {
|
|
48
|
+
const oneDayAgo = new Date();
|
|
49
|
+
oneDayAgo.setHours(oneDayAgo.getHours() - 24);
|
|
50
|
+
|
|
51
|
+
const usersToDelete = await (
|
|
52
|
+
await strapi.query('plugin::users-permissions.user').findMany({
|
|
53
|
+
where: {
|
|
54
|
+
$and: [
|
|
55
|
+
{
|
|
56
|
+
confirmed: {
|
|
57
|
+
$eq: false
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
createdAt: {
|
|
62
|
+
$lt: oneDayAgo
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
).map((user) => {
|
|
69
|
+
return user.id;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
await strapi.query('plugin::users-permissions.user').deleteMany({
|
|
74
|
+
where: {
|
|
75
|
+
id: {
|
|
76
|
+
$in: usersToDelete
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.log(error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PAGE_UID } from '../../../shared/utils/constants';
|
|
2
|
+
|
|
3
|
+
export const extendPage = () => {
|
|
4
|
+
const pageContentType = strapi.contentType(PAGE_UID);
|
|
5
|
+
pageContentType.attributes = {
|
|
6
|
+
...pageContentType.attributes,
|
|
7
|
+
isProtected: {
|
|
8
|
+
type: 'boolean',
|
|
9
|
+
required: false,
|
|
10
|
+
default: false
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
delete pageContentType.attributes.username;
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PLATFORM_UID } from '../../../shared/utils/constants';
|
|
2
|
+
|
|
3
|
+
export const extendPlatform = () => {
|
|
4
|
+
const platformContentType = strapi.contentType(PLATFORM_UID);
|
|
5
|
+
platformContentType.attributes = {
|
|
6
|
+
...platformContentType.attributes,
|
|
7
|
+
isProtected: {
|
|
8
|
+
type: 'boolean',
|
|
9
|
+
required: false,
|
|
10
|
+
default: false
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
delete platformContentType.attributes.username;
|
|
14
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { validateYupSchema, yup } from '@strapi/utils';
|
|
2
|
+
|
|
3
|
+
const registerSchema = yup.object({
|
|
4
|
+
email: yup.string().email().required(),
|
|
5
|
+
password: yup.string().required(),
|
|
6
|
+
platformId: yup.number().required()
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const loginSchema = yup.object({
|
|
10
|
+
email: yup.string().email().required(),
|
|
11
|
+
password: yup.string().required(),
|
|
12
|
+
platformId: yup.number().required()
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const forgotPasswordSchema = yup.object({
|
|
16
|
+
email: yup.string().email().required(),
|
|
17
|
+
platformId: yup.number().required()
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const resetPasswordSchema = yup.object({
|
|
21
|
+
password: yup.string().required(),
|
|
22
|
+
resetPasswordToken: yup.string().required()
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const validateRegisterSchema = async (input: any) => validateYupSchema(input, registerSchema);
|
|
26
|
+
export const validateLoginSchema = async (input: any) => validateYupSchema(input, loginSchema);
|
|
27
|
+
export const validateForgotPasswordSchema = async (input: any) => validateYupSchema(input, forgotPasswordSchema);
|
|
28
|
+
export const validateResetPasswordSchema = async (input: any) => validateYupSchema(input, resetPasswordSchema);
|