@strapi/plugin-users-permissions 0.0.0-next.e9bb5ccdc459f4c6b6717a2d5d86359b7a47d47d → 0.0.0-next.eba25ec571b091c6bde1104eb6c753debdf15462
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/.eslintignore +1 -2
- package/.eslintrc +17 -0
- package/LICENSE +18 -3
- package/admin/src/components/BoundRoute/{index.js → index.jsx} +6 -4
- package/admin/src/components/FormModal/Input/{index.js → index.jsx} +37 -33
- package/admin/src/components/FormModal/index.jsx +115 -0
- package/admin/src/components/Permissions/PermissionRow/{CheckboxWrapper.js → CheckboxWrapper.jsx} +4 -3
- package/admin/src/components/Permissions/PermissionRow/{SubCategory.js → SubCategory.jsx} +27 -15
- package/admin/src/components/Permissions/PermissionRow/{index.js → index.jsx} +4 -2
- package/admin/src/components/Permissions/index.jsx +47 -0
- package/admin/src/components/Permissions/reducer.js +1 -1
- package/admin/src/components/Policies/{index.js → index.jsx} +9 -6
- package/admin/src/components/UsersPermissions/{index.js → index.jsx} +22 -11
- package/admin/src/components/UsersPermissions/reducer.js +1 -1
- package/admin/src/{permissions.js → constants.js} +1 -3
- package/admin/src/contexts/UsersPermissionsContext/{index.js → index.jsx} +1 -0
- package/admin/src/index.js +25 -51
- package/admin/src/pages/AdvancedSettings/index.jsx +214 -0
- package/admin/src/pages/AdvancedSettings/utils/layout.js +20 -35
- package/admin/src/pages/AdvancedSettings/utils/schema.js +5 -2
- package/admin/src/pages/EmailTemplates/components/EmailForm.jsx +156 -0
- package/admin/src/pages/EmailTemplates/components/{EmailTable.js → EmailTable.jsx} +27 -22
- package/admin/src/pages/EmailTemplates/index.jsx +148 -0
- package/admin/src/pages/EmailTemplates/utils/schema.js +18 -6
- package/admin/src/pages/Providers/index.jsx +262 -0
- package/admin/src/pages/Providers/utils/forms.js +23 -11
- package/admin/src/pages/Roles/constants.js +7 -0
- package/admin/src/pages/Roles/hooks/usePlugins.js +78 -0
- package/admin/src/pages/Roles/index.jsx +24 -0
- package/admin/src/pages/Roles/pages/CreatePage.jsx +194 -0
- package/admin/src/pages/Roles/pages/EditPage.jsx +215 -0
- package/admin/src/pages/Roles/pages/ListPage/components/TableBody.jsx +119 -0
- package/admin/src/pages/Roles/{ListPage/index.js → pages/ListPage/index.jsx} +108 -83
- package/admin/src/translations/en.json +1 -1
- package/admin/src/translations/zh-Hans.json +80 -80
- package/admin/src/utils/index.js +1 -2
- package/admin/src/utils/prefixPluginTranslations.js +13 -0
- package/dist/_chunks/ar-BguGUqwK.js +44 -0
- package/dist/_chunks/ar-BguGUqwK.js.map +1 -0
- package/dist/_chunks/ar-CK8BRRXB.mjs +44 -0
- package/dist/_chunks/ar-CK8BRRXB.mjs.map +1 -0
- package/dist/_chunks/cs-BVigMk0l.mjs +50 -0
- package/dist/_chunks/cs-BVigMk0l.mjs.map +1 -0
- package/dist/_chunks/cs-BW8-K_GY.js +50 -0
- package/dist/_chunks/cs-BW8-K_GY.js.map +1 -0
- package/dist/_chunks/de-BKUdRFI4.mjs +62 -0
- package/dist/_chunks/de-BKUdRFI4.mjs.map +1 -0
- package/dist/_chunks/de-owXpVluI.js +62 -0
- package/dist/_chunks/de-owXpVluI.js.map +1 -0
- package/dist/_chunks/dk-BQiTK50l.mjs +86 -0
- package/dist/_chunks/dk-BQiTK50l.mjs.map +1 -0
- package/dist/_chunks/dk-LXAnbuBk.js +86 -0
- package/dist/_chunks/dk-LXAnbuBk.js.map +1 -0
- package/dist/_chunks/en-DOHtPf-2.mjs +86 -0
- package/dist/_chunks/en-DOHtPf-2.mjs.map +1 -0
- package/dist/_chunks/en-MHo5mcsU.js +86 -0
- package/dist/_chunks/en-MHo5mcsU.js.map +1 -0
- package/dist/_chunks/es-BwLCLXAQ.js +86 -0
- package/dist/_chunks/es-BwLCLXAQ.js.map +1 -0
- package/dist/_chunks/es-DNgOVMjD.mjs +86 -0
- package/dist/_chunks/es-DNgOVMjD.mjs.map +1 -0
- package/dist/_chunks/fr-DkgRugiU.mjs +50 -0
- package/dist/_chunks/fr-DkgRugiU.mjs.map +1 -0
- package/dist/_chunks/fr-DkhpSjjm.js +50 -0
- package/dist/_chunks/fr-DkhpSjjm.js.map +1 -0
- package/dist/_chunks/id-BTemOeTZ.js +62 -0
- package/dist/_chunks/id-BTemOeTZ.js.map +1 -0
- package/dist/_chunks/id-BdEsvnaF.mjs +62 -0
- package/dist/_chunks/id-BdEsvnaF.mjs.map +1 -0
- package/dist/_chunks/index-B31GwOBY.js +1172 -0
- package/dist/_chunks/index-B31GwOBY.js.map +1 -0
- package/dist/_chunks/index-BnX71_B4-BeiPUoDw.mjs +12005 -0
- package/dist/_chunks/index-BnX71_B4-BeiPUoDw.mjs.map +1 -0
- package/dist/_chunks/index-BnX71_B4-BwTVUy-u.js +12029 -0
- package/dist/_chunks/index-BnX71_B4-BwTVUy-u.js.map +1 -0
- package/dist/_chunks/index-Bzdgm3YY.js +247 -0
- package/dist/_chunks/index-Bzdgm3YY.js.map +1 -0
- package/dist/_chunks/index-CH7DTQRg.js +281 -0
- package/dist/_chunks/index-CH7DTQRg.js.map +1 -0
- package/dist/_chunks/index-DQjBkqk6.mjs +1142 -0
- package/dist/_chunks/index-DQjBkqk6.mjs.map +1 -0
- package/dist/_chunks/index-DS3khL98.js +366 -0
- package/dist/_chunks/index-DS3khL98.js.map +1 -0
- package/dist/_chunks/index-Dby0-3V3.mjs +248 -0
- package/dist/_chunks/index-Dby0-3V3.mjs.map +1 -0
- package/dist/_chunks/index-DkLfQU9x.js +640 -0
- package/dist/_chunks/index-DkLfQU9x.js.map +1 -0
- package/dist/_chunks/index-YiI4HHBF.mjs +262 -0
- package/dist/_chunks/index-YiI4HHBF.mjs.map +1 -0
- package/dist/_chunks/index-og30lh2q.mjs +617 -0
- package/dist/_chunks/index-og30lh2q.mjs.map +1 -0
- package/dist/_chunks/index-rj9z5xOr.mjs +344 -0
- package/dist/_chunks/index-rj9z5xOr.mjs.map +1 -0
- package/dist/_chunks/it-B-rv0E24.mjs +62 -0
- package/dist/_chunks/it-B-rv0E24.mjs.map +1 -0
- package/dist/_chunks/it-D1rH6V6_.js +62 -0
- package/dist/_chunks/it-D1rH6V6_.js.map +1 -0
- package/dist/_chunks/ja-C8K-VBPD.mjs +48 -0
- package/dist/_chunks/ja-C8K-VBPD.mjs.map +1 -0
- package/dist/_chunks/ja-DqShgTMf.js +48 -0
- package/dist/_chunks/ja-DqShgTMf.js.map +1 -0
- package/dist/_chunks/ko-B9DGEPWH.js +86 -0
- package/dist/_chunks/ko-B9DGEPWH.js.map +1 -0
- package/dist/_chunks/ko-Busb0wIY.mjs +86 -0
- package/dist/_chunks/ko-Busb0wIY.mjs.map +1 -0
- package/dist/_chunks/ms-ByvsQjRt.mjs +49 -0
- package/dist/_chunks/ms-ByvsQjRt.mjs.map +1 -0
- package/dist/_chunks/ms-CPBU3LWf.js +49 -0
- package/dist/_chunks/ms-CPBU3LWf.js.map +1 -0
- package/dist/_chunks/nl-5qO8Rpcy.mjs +48 -0
- package/dist/_chunks/nl-5qO8Rpcy.mjs.map +1 -0
- package/dist/_chunks/nl-CwNB6YoO.js +48 -0
- package/dist/_chunks/nl-CwNB6YoO.js.map +1 -0
- package/dist/_chunks/pl-BdIzifBE.mjs +86 -0
- package/dist/_chunks/pl-BdIzifBE.mjs.map +1 -0
- package/dist/_chunks/pl-Do9UD69f.js +86 -0
- package/dist/_chunks/pl-Do9UD69f.js.map +1 -0
- package/dist/_chunks/pt-BIO24ioG.mjs +48 -0
- package/dist/_chunks/pt-BIO24ioG.mjs.map +1 -0
- package/dist/_chunks/pt-BR-D7dZhxuP.js +44 -0
- package/dist/_chunks/pt-BR-D7dZhxuP.js.map +1 -0
- package/dist/_chunks/pt-BR-f0p23AQZ.mjs +44 -0
- package/dist/_chunks/pt-BR-f0p23AQZ.mjs.map +1 -0
- package/dist/_chunks/pt-fdvyOnUp.js +48 -0
- package/dist/_chunks/pt-fdvyOnUp.js.map +1 -0
- package/dist/_chunks/ru-C94rjPGA.js +86 -0
- package/dist/_chunks/ru-C94rjPGA.js.map +1 -0
- package/dist/_chunks/ru-VWy-IB7K.mjs +86 -0
- package/dist/_chunks/ru-VWy-IB7K.mjs.map +1 -0
- package/dist/_chunks/sk-BABEhykl.js +50 -0
- package/dist/_chunks/sk-BABEhykl.js.map +1 -0
- package/dist/_chunks/sk-B_LIcepm.mjs +50 -0
- package/dist/_chunks/sk-B_LIcepm.mjs.map +1 -0
- package/dist/_chunks/sv-ABLKOokl.mjs +86 -0
- package/dist/_chunks/sv-ABLKOokl.mjs.map +1 -0
- package/dist/_chunks/sv-Be43LhA9.js +86 -0
- package/dist/_chunks/sv-Be43LhA9.js.map +1 -0
- package/dist/_chunks/th-DKyP7ueR.mjs +60 -0
- package/dist/_chunks/th-DKyP7ueR.mjs.map +1 -0
- package/dist/_chunks/th-DgVhVLhL.js +60 -0
- package/dist/_chunks/th-DgVhVLhL.js.map +1 -0
- package/dist/_chunks/tr-B_idhkEs.js +85 -0
- package/dist/_chunks/tr-B_idhkEs.js.map +1 -0
- package/dist/_chunks/tr-qa1Q5UjC.mjs +85 -0
- package/dist/_chunks/tr-qa1Q5UjC.mjs.map +1 -0
- package/dist/_chunks/uk-BmRqbeQc.mjs +49 -0
- package/dist/_chunks/uk-BmRqbeQc.mjs.map +1 -0
- package/dist/_chunks/uk-LHOivnhP.js +49 -0
- package/dist/_chunks/uk-LHOivnhP.js.map +1 -0
- package/dist/_chunks/vi-CdVRdKDw.js +50 -0
- package/dist/_chunks/vi-CdVRdKDw.js.map +1 -0
- package/dist/_chunks/vi-HW-EdMea.mjs +50 -0
- package/dist/_chunks/vi-HW-EdMea.mjs.map +1 -0
- package/dist/_chunks/zh-5hKkVPA4.mjs +86 -0
- package/dist/_chunks/zh-5hKkVPA4.mjs.map +1 -0
- package/dist/_chunks/zh-Cuq8gMnF.js +86 -0
- package/dist/_chunks/zh-Cuq8gMnF.js.map +1 -0
- package/dist/_chunks/zh-Hans-BHilK-yc.mjs +86 -0
- package/dist/_chunks/zh-Hans-BHilK-yc.mjs.map +1 -0
- package/dist/_chunks/zh-Hans-GQDMKtY4.js +86 -0
- package/dist/_chunks/zh-Hans-GQDMKtY4.js.map +1 -0
- package/dist/admin/index.js +4 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/index.mjs +5 -0
- package/dist/admin/index.mjs.map +1 -0
- package/documentation/content-api.yaml +1 -1
- package/jest.config.front.js +1 -0
- package/package.json +51 -35
- package/packup.config.ts +22 -0
- package/server/bootstrap/index.js +18 -15
- package/server/bootstrap/users-permissions-actions.js +6 -0
- package/server/config.js +29 -0
- package/server/content-types/user/index.js +0 -1
- package/server/controllers/auth.js +74 -38
- package/server/controllers/content-manager-user.js +28 -30
- package/server/controllers/role.js +17 -4
- package/server/controllers/user.js +18 -8
- package/server/controllers/validation/auth.js +81 -25
- package/server/graphql/types/index.js +1 -0
- package/server/graphql/types/user-input.js +20 -0
- package/server/middlewares/rateLimit.js +41 -21
- package/server/register.js +1 -1
- package/server/services/jwt.js +3 -3
- package/server/services/permission.js +3 -7
- package/server/services/providers-registry.js +469 -261
- package/server/services/providers.js +10 -5
- package/server/services/role.js +15 -13
- package/server/services/user.js +56 -19
- package/server/services/users-permissions.js +15 -13
- package/server/strategies/users-permissions.js +1 -8
- package/server/utils/index.d.ts +2 -1
- package/server/utils/sanitize/sanitizers.js +7 -3
- package/server/utils/sanitize/visitors/remove-user-relation-from-role-entities.js +2 -2
- package/.eslintrc.js +0 -14
- package/admin/src/components/FormModal/index.js +0 -123
- package/admin/src/components/Permissions/index.js +0 -54
- package/admin/src/hooks/index.js +0 -5
- package/admin/src/hooks/useFetchRole/index.js +0 -64
- package/admin/src/hooks/useFetchRole/reducer.js +0 -31
- package/admin/src/hooks/useForm/index.js +0 -67
- package/admin/src/hooks/useForm/reducer.js +0 -40
- package/admin/src/hooks/usePlugins/index.js +0 -67
- package/admin/src/hooks/usePlugins/init.js +0 -5
- package/admin/src/hooks/usePlugins/reducer.js +0 -34
- package/admin/src/hooks/useRolesList/index.js +0 -62
- package/admin/src/hooks/useRolesList/init.js +0 -5
- package/admin/src/hooks/useRolesList/reducer.js +0 -31
- package/admin/src/pages/AdvancedSettings/index.js +0 -243
- package/admin/src/pages/AdvancedSettings/utils/api.js +0 -17
- package/admin/src/pages/EmailTemplates/components/EmailForm.js +0 -175
- package/admin/src/pages/EmailTemplates/index.js +0 -160
- package/admin/src/pages/EmailTemplates/utils/api.js +0 -17
- package/admin/src/pages/Providers/index.js +0 -272
- package/admin/src/pages/Providers/reducer.js +0 -54
- package/admin/src/pages/Providers/utils/api.js +0 -25
- package/admin/src/pages/Providers/utils/createProvidersArray.js +0 -21
- package/admin/src/pages/Roles/CreatePage/index.js +0 -182
- package/admin/src/pages/Roles/CreatePage/utils/schema.js +0 -9
- package/admin/src/pages/Roles/EditPage/index.js +0 -194
- package/admin/src/pages/Roles/EditPage/utils/schema.js +0 -9
- package/admin/src/pages/Roles/ListPage/components/TableBody.js +0 -92
- package/admin/src/pages/Roles/ListPage/utils/api.js +0 -31
- package/admin/src/pages/Roles/ProtectedCreatePage/index.js +0 -12
- package/admin/src/pages/Roles/ProtectedEditPage/index.js +0 -12
- package/admin/src/pages/Roles/ProtectedListPage/index.js +0 -15
- package/admin/src/pages/Roles/index.js +0 -27
- package/admin/src/utils/getRequestURL.js +0 -5
- package/server/bootstrap/grant-config.js +0 -131
- package/strapi-admin.js +0 -3
- package/strapi-server.js +0 -3
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
|
-
const {
|
|
4
|
+
const { async, errors } = require('@strapi/utils');
|
|
5
5
|
const { getService } = require('../utils');
|
|
6
6
|
const { validateDeleteRoleBody } = require('./validation/user');
|
|
7
7
|
|
|
8
|
+
const { ApplicationError, ValidationError } = errors;
|
|
9
|
+
|
|
10
|
+
const sanitizeOutput = async (role) => {
|
|
11
|
+
const { sanitizeLocalizationFields } = strapi.plugin('i18n').service('sanitize');
|
|
12
|
+
const schema = strapi.getModel('plugin::users-permissions.role');
|
|
13
|
+
|
|
14
|
+
return async.pipe(sanitizeLocalizationFields(schema))(role);
|
|
15
|
+
};
|
|
16
|
+
|
|
8
17
|
module.exports = {
|
|
9
18
|
/**
|
|
10
19
|
* Default action.
|
|
@@ -30,13 +39,17 @@ module.exports = {
|
|
|
30
39
|
return ctx.notFound();
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
|
|
42
|
+
const safeRole = await sanitizeOutput(role);
|
|
43
|
+
|
|
44
|
+
ctx.send({ role: safeRole });
|
|
34
45
|
},
|
|
35
46
|
|
|
36
47
|
async find(ctx) {
|
|
37
48
|
const roles = await getService('role').find();
|
|
38
49
|
|
|
39
|
-
|
|
50
|
+
const safeRoles = await Promise.all(roles.map(sanitizeOutput));
|
|
51
|
+
|
|
52
|
+
ctx.send({ roles: safeRoles });
|
|
40
53
|
},
|
|
41
54
|
|
|
42
55
|
async updateRole(ctx) {
|
|
@@ -59,7 +72,7 @@ module.exports = {
|
|
|
59
72
|
}
|
|
60
73
|
|
|
61
74
|
// Fetch public role.
|
|
62
|
-
const publicRole = await strapi
|
|
75
|
+
const publicRole = await strapi.db
|
|
63
76
|
.query('plugin::users-permissions.role')
|
|
64
77
|
.findOne({ where: { type: 'public' } });
|
|
65
78
|
|
|
@@ -11,21 +11,27 @@ const utils = require('@strapi/utils');
|
|
|
11
11
|
const { getService } = require('../utils');
|
|
12
12
|
const { validateCreateUserBody, validateUpdateUserBody } = require('./validation/user');
|
|
13
13
|
|
|
14
|
-
const { sanitize } = utils;
|
|
15
14
|
const { ApplicationError, ValidationError, NotFoundError } = utils.errors;
|
|
16
15
|
|
|
17
16
|
const sanitizeOutput = async (user, ctx) => {
|
|
18
17
|
const schema = strapi.getModel('plugin::users-permissions.user');
|
|
19
18
|
const { auth } = ctx.state;
|
|
20
19
|
|
|
21
|
-
return
|
|
20
|
+
return strapi.contentAPI.sanitize.output(user, schema, { auth });
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const validateQuery = async (query, ctx) => {
|
|
24
|
+
const schema = strapi.getModel('plugin::users-permissions.user');
|
|
25
|
+
const { auth } = ctx.state;
|
|
26
|
+
|
|
27
|
+
return strapi.contentAPI.validate.query(query, schema, { auth });
|
|
22
28
|
};
|
|
23
29
|
|
|
24
30
|
const sanitizeQuery = async (query, ctx) => {
|
|
25
31
|
const schema = strapi.getModel('plugin::users-permissions.user');
|
|
26
32
|
const { auth } = ctx.state;
|
|
27
33
|
|
|
28
|
-
return
|
|
34
|
+
return strapi.contentAPI.sanitize.query(query, schema, { auth });
|
|
29
35
|
};
|
|
30
36
|
|
|
31
37
|
module.exports = {
|
|
@@ -42,7 +48,7 @@ module.exports = {
|
|
|
42
48
|
|
|
43
49
|
const { email, username, role } = ctx.request.body;
|
|
44
50
|
|
|
45
|
-
const userWithSameUsername = await strapi
|
|
51
|
+
const userWithSameUsername = await strapi.db
|
|
46
52
|
.query('plugin::users-permissions.user')
|
|
47
53
|
.findOne({ where: { username } });
|
|
48
54
|
|
|
@@ -51,7 +57,7 @@ module.exports = {
|
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
if (advanced.unique_email) {
|
|
54
|
-
const userWithSameEmail = await strapi
|
|
60
|
+
const userWithSameEmail = await strapi.db
|
|
55
61
|
.query('plugin::users-permissions.user')
|
|
56
62
|
.findOne({ where: { email: email.toLowerCase() } });
|
|
57
63
|
|
|
@@ -67,7 +73,7 @@ module.exports = {
|
|
|
67
73
|
};
|
|
68
74
|
|
|
69
75
|
if (!role) {
|
|
70
|
-
const defaultRole = await strapi
|
|
76
|
+
const defaultRole = await strapi.db
|
|
71
77
|
.query('plugin::users-permissions.role')
|
|
72
78
|
.findOne({ where: { type: advanced.default_role } });
|
|
73
79
|
|
|
@@ -108,7 +114,7 @@ module.exports = {
|
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
if (_.has(ctx.request.body, 'username')) {
|
|
111
|
-
const userWithSameUsername = await strapi
|
|
117
|
+
const userWithSameUsername = await strapi.db
|
|
112
118
|
.query('plugin::users-permissions.user')
|
|
113
119
|
.findOne({ where: { username } });
|
|
114
120
|
|
|
@@ -118,7 +124,7 @@ module.exports = {
|
|
|
118
124
|
}
|
|
119
125
|
|
|
120
126
|
if (_.has(ctx.request.body, 'email') && advancedConfigs.unique_email) {
|
|
121
|
-
const userWithSameEmail = await strapi
|
|
127
|
+
const userWithSameEmail = await strapi.db
|
|
122
128
|
.query('plugin::users-permissions.user')
|
|
123
129
|
.findOne({ where: { email: email.toLowerCase() } });
|
|
124
130
|
|
|
@@ -143,6 +149,7 @@ module.exports = {
|
|
|
143
149
|
* @return {Object|Array}
|
|
144
150
|
*/
|
|
145
151
|
async find(ctx) {
|
|
152
|
+
await validateQuery(ctx.query, ctx);
|
|
146
153
|
const sanitizedQuery = await sanitizeQuery(ctx.query, ctx);
|
|
147
154
|
const users = await getService('user').fetchAll(sanitizedQuery);
|
|
148
155
|
|
|
@@ -155,6 +162,7 @@ module.exports = {
|
|
|
155
162
|
*/
|
|
156
163
|
async findOne(ctx) {
|
|
157
164
|
const { id } = ctx.params;
|
|
165
|
+
await validateQuery(ctx.query, ctx);
|
|
158
166
|
const sanitizedQuery = await sanitizeQuery(ctx.query, ctx);
|
|
159
167
|
|
|
160
168
|
let data = await getService('user').fetch(id, sanitizedQuery);
|
|
@@ -171,6 +179,7 @@ module.exports = {
|
|
|
171
179
|
* @return {Number}
|
|
172
180
|
*/
|
|
173
181
|
async count(ctx) {
|
|
182
|
+
await validateQuery(ctx.query, ctx);
|
|
174
183
|
const sanitizedQuery = await sanitizeQuery(ctx.query, ctx);
|
|
175
184
|
|
|
176
185
|
ctx.body = await getService('user').count(sanitizedQuery);
|
|
@@ -201,6 +210,7 @@ module.exports = {
|
|
|
201
210
|
return ctx.unauthorized();
|
|
202
211
|
}
|
|
203
212
|
|
|
213
|
+
await validateQuery(query, ctx);
|
|
204
214
|
const sanitizedQuery = await sanitizeQuery(query, ctx);
|
|
205
215
|
const user = await getService('user').fetch(authUser.id, sanitizedQuery);
|
|
206
216
|
|
|
@@ -7,11 +7,27 @@ const callbackSchema = yup.object({
|
|
|
7
7
|
password: yup.string().required(),
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const createRegisterSchema = (config) =>
|
|
11
|
+
yup.object({
|
|
12
|
+
email: yup.string().email().required(),
|
|
13
|
+
username: yup.string().required(),
|
|
14
|
+
password: yup
|
|
15
|
+
.string()
|
|
16
|
+
.required()
|
|
17
|
+
.test(async function (value) {
|
|
18
|
+
if (typeof config?.validatePassword === 'function') {
|
|
19
|
+
try {
|
|
20
|
+
const isValid = await config.validatePassword(value);
|
|
21
|
+
if (!isValid) {
|
|
22
|
+
return this.createError({ message: 'Password validation failed.' });
|
|
23
|
+
}
|
|
24
|
+
} catch (error) {
|
|
25
|
+
return this.createError({ message: error.message || 'An error occurred.' });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
15
31
|
|
|
16
32
|
const sendEmailConfirmationSchema = yup.object({
|
|
17
33
|
email: yup.string().email().required(),
|
|
@@ -27,31 +43,71 @@ const forgotPasswordSchema = yup
|
|
|
27
43
|
})
|
|
28
44
|
.noUnknown();
|
|
29
45
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
46
|
+
const createResetPasswordSchema = (config) =>
|
|
47
|
+
yup
|
|
48
|
+
.object({
|
|
49
|
+
password: yup
|
|
50
|
+
.string()
|
|
51
|
+
.required()
|
|
52
|
+
.test(async function (value) {
|
|
53
|
+
if (typeof config?.validatePassword === 'function') {
|
|
54
|
+
try {
|
|
55
|
+
const isValid = await config.validatePassword(value);
|
|
56
|
+
if (!isValid) {
|
|
57
|
+
return this.createError({ message: 'Password validation failed.' });
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
return this.createError({ message: error.message || 'An error occurred.' });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}),
|
|
37
65
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
.required()
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
66
|
+
passwordConfirmation: yup
|
|
67
|
+
.string()
|
|
68
|
+
.required()
|
|
69
|
+
.oneOf([yup.ref('password')], 'Passwords do not match'),
|
|
70
|
+
|
|
71
|
+
code: yup.string().required(),
|
|
72
|
+
})
|
|
73
|
+
.noUnknown();
|
|
74
|
+
|
|
75
|
+
const createChangePasswordSchema = (config) =>
|
|
76
|
+
yup
|
|
77
|
+
.object({
|
|
78
|
+
password: yup
|
|
79
|
+
.string()
|
|
80
|
+
.required()
|
|
81
|
+
.test(async function (value) {
|
|
82
|
+
if (typeof config?.validatePassword === 'function') {
|
|
83
|
+
try {
|
|
84
|
+
const isValid = await config.validatePassword(value);
|
|
85
|
+
if (!isValid) {
|
|
86
|
+
return this.createError({ message: 'Password validation failed.' });
|
|
87
|
+
}
|
|
88
|
+
} catch (error) {
|
|
89
|
+
return this.createError({ message: error.message || 'An error occurred.' });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}),
|
|
94
|
+
passwordConfirmation: yup
|
|
95
|
+
.string()
|
|
96
|
+
.required()
|
|
97
|
+
.oneOf([yup.ref('password')], 'Passwords do not match'),
|
|
98
|
+
currentPassword: yup.string().required(),
|
|
99
|
+
})
|
|
100
|
+
.noUnknown();
|
|
48
101
|
|
|
49
102
|
module.exports = {
|
|
50
103
|
validateCallbackBody: validateYupSchema(callbackSchema),
|
|
51
|
-
validateRegisterBody:
|
|
104
|
+
validateRegisterBody: (payload, config) =>
|
|
105
|
+
validateYupSchema(createRegisterSchema(config))(payload),
|
|
52
106
|
validateSendEmailConfirmationBody: validateYupSchema(sendEmailConfirmationSchema),
|
|
53
107
|
validateEmailConfirmationBody: validateYupSchema(validateEmailConfirmationSchema),
|
|
54
108
|
validateForgotPasswordBody: validateYupSchema(forgotPasswordSchema),
|
|
55
|
-
validateResetPasswordBody:
|
|
56
|
-
|
|
109
|
+
validateResetPasswordBody: (payload, config) =>
|
|
110
|
+
validateYupSchema(createResetPasswordSchema(config))(payload),
|
|
111
|
+
validateChangePasswordBody: (payload, config) =>
|
|
112
|
+
validateYupSchema(createChangePasswordSchema(config))(payload),
|
|
57
113
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const usersPermissionsUserUID = 'plugin::users-permissions.user';
|
|
4
|
+
|
|
5
|
+
module.exports = ({ nexus, strapi }) => {
|
|
6
|
+
const { getContentTypeInputName } = strapi.plugin('graphql').service('utils').naming;
|
|
7
|
+
|
|
8
|
+
const userContentType = strapi.getModel(usersPermissionsUserUID);
|
|
9
|
+
const userInputName = getContentTypeInputName(userContentType);
|
|
10
|
+
|
|
11
|
+
return nexus.extendInputType({
|
|
12
|
+
type: userInputName,
|
|
13
|
+
|
|
14
|
+
definition(t) {
|
|
15
|
+
// Manually add the private password field back to the data
|
|
16
|
+
// input type as it is used for CRUD operations on users
|
|
17
|
+
t.string('password');
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
};
|
|
@@ -1,27 +1,47 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const utils = require('@strapi/utils');
|
|
5
|
+
const { isString, has, toLower } = require('lodash/fp');
|
|
6
|
+
|
|
7
|
+
const { RateLimitError } = utils.errors;
|
|
8
|
+
|
|
3
9
|
module.exports =
|
|
4
10
|
(config, { strapi }) =>
|
|
5
11
|
async (ctx, next) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
let rateLimitConfig = strapi.config.get('plugin::users-permissions.ratelimit');
|
|
13
|
+
|
|
14
|
+
if (!rateLimitConfig) {
|
|
15
|
+
rateLimitConfig = {
|
|
16
|
+
enabled: true,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!has('enabled', rateLimitConfig)) {
|
|
21
|
+
rateLimitConfig.enabled = true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (rateLimitConfig.enabled === true) {
|
|
25
|
+
const rateLimit = require('koa2-ratelimit').RateLimit;
|
|
26
|
+
|
|
27
|
+
const userIdentifier = toLower(ctx.request.body.email) || 'unknownIdentifier';
|
|
28
|
+
const requestPath = isString(ctx.request.path)
|
|
29
|
+
? toLower(path.normalize(ctx.request.path))
|
|
30
|
+
: 'invalidPath';
|
|
31
|
+
|
|
32
|
+
const loadConfig = {
|
|
33
|
+
interval: { min: 5 },
|
|
34
|
+
max: 5,
|
|
35
|
+
prefixKey: `${userIdentifier}:${requestPath}:${ctx.request.ip}`,
|
|
36
|
+
handler() {
|
|
37
|
+
throw new RateLimitError();
|
|
38
|
+
},
|
|
39
|
+
...rateLimitConfig,
|
|
40
|
+
...config,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return rateLimit.middleware(loadConfig)(ctx, next);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return next();
|
|
27
47
|
};
|
package/server/register.js
CHANGED
|
@@ -7,7 +7,7 @@ const authStrategy = require('./strategies/users-permissions');
|
|
|
7
7
|
const sanitizers = require('./utils/sanitize/sanitizers');
|
|
8
8
|
|
|
9
9
|
module.exports = ({ strapi }) => {
|
|
10
|
-
strapi.
|
|
10
|
+
strapi.get('auth').register('content-api', authStrategy);
|
|
11
11
|
strapi.sanitizers.add('content-api.output', sanitizers.defaultSanitizeOutput);
|
|
12
12
|
|
|
13
13
|
if (strapi.plugin('graphql')) {
|
package/server/services/jwt.js
CHANGED
|
@@ -29,10 +29,10 @@ module.exports = ({ strapi }) => ({
|
|
|
29
29
|
},
|
|
30
30
|
|
|
31
31
|
issue(payload, jwtOptions = {}) {
|
|
32
|
-
_.defaults(jwtOptions, strapi.config.get('plugin
|
|
32
|
+
_.defaults(jwtOptions, strapi.config.get('plugin::users-permissions.jwt'));
|
|
33
33
|
return jwt.sign(
|
|
34
34
|
_.clone(payload.toJSON ? payload.toJSON() : payload),
|
|
35
|
-
strapi.config.get('plugin
|
|
35
|
+
strapi.config.get('plugin::users-permissions.jwtSecret'),
|
|
36
36
|
jwtOptions
|
|
37
37
|
);
|
|
38
38
|
},
|
|
@@ -41,7 +41,7 @@ module.exports = ({ strapi }) => ({
|
|
|
41
41
|
return new Promise((resolve, reject) => {
|
|
42
42
|
jwt.verify(
|
|
43
43
|
token,
|
|
44
|
-
strapi.config.get('plugin
|
|
44
|
+
strapi.config.get('plugin::users-permissions.jwtSecret'),
|
|
45
45
|
{},
|
|
46
46
|
(err, tokenPayload = {}) => {
|
|
47
47
|
if (err) {
|
|
@@ -11,11 +11,7 @@ module.exports = ({ strapi }) => ({
|
|
|
11
11
|
* @return {object[]}
|
|
12
12
|
*/
|
|
13
13
|
async findRolePermissions(roleID) {
|
|
14
|
-
return strapi.
|
|
15
|
-
'plugin::users-permissions.role',
|
|
16
|
-
{ id: roleID },
|
|
17
|
-
'permissions'
|
|
18
|
-
);
|
|
14
|
+
return strapi.db.query('plugin::users-permissions.role').load({ id: roleID }, 'permissions');
|
|
19
15
|
},
|
|
20
16
|
|
|
21
17
|
/**
|
|
@@ -24,8 +20,8 @@ module.exports = ({ strapi }) => ({
|
|
|
24
20
|
* @return {object[]}
|
|
25
21
|
*/
|
|
26
22
|
async findPublicPermissions() {
|
|
27
|
-
return strapi.
|
|
28
|
-
|
|
23
|
+
return strapi.db.query('plugin::users-permissions.permission').findMany({
|
|
24
|
+
where: PUBLIC_ROLE_FILTER,
|
|
29
25
|
});
|
|
30
26
|
},
|
|
31
27
|
|