@strapi/plugin-users-permissions 4.0.0-next.7 → 4.0.1
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/admin/src/components/BoundRoute/getMethodColor.js +41 -0
- package/admin/src/components/BoundRoute/index.js +40 -24
- package/admin/src/components/FormModal/Input/index.js +121 -0
- package/admin/src/components/FormModal/index.js +123 -0
- package/admin/src/components/Permissions/PermissionRow/CheckboxWrapper.js +19 -26
- package/admin/src/components/Permissions/PermissionRow/SubCategory.js +118 -0
- package/admin/src/components/Permissions/PermissionRow/index.js +9 -48
- package/admin/src/components/Permissions/index.js +36 -24
- package/admin/src/components/Permissions/init.js +1 -6
- package/admin/src/components/Policies/index.js +46 -47
- package/admin/src/components/UsersPermissions/index.js +29 -26
- package/admin/src/components/UsersPermissions/init.js +1 -2
- package/admin/src/hooks/useFetchRole/index.js +17 -7
- package/admin/src/hooks/useForm/index.js +3 -29
- package/admin/src/hooks/useForm/reducer.js +2 -21
- package/admin/src/hooks/usePlugins/index.js +12 -21
- package/admin/src/hooks/usePlugins/reducer.js +0 -3
- package/admin/src/index.js +29 -34
- package/admin/src/pages/AdvancedSettings/index.js +210 -193
- package/admin/src/pages/AdvancedSettings/utils/api.js +13 -0
- package/admin/src/pages/AdvancedSettings/utils/layout.js +96 -0
- package/admin/src/pages/AdvancedSettings/utils/schema.js +21 -0
- package/admin/src/pages/EmailTemplates/components/EmailForm.js +173 -0
- package/admin/src/pages/EmailTemplates/components/EmailTable.js +116 -0
- package/admin/src/pages/EmailTemplates/index.js +125 -198
- package/admin/src/pages/EmailTemplates/utils/api.js +13 -0
- package/admin/src/pages/Providers/index.js +208 -216
- package/admin/src/pages/Providers/utils/api.js +21 -0
- package/admin/src/pages/Providers/utils/forms.js +168 -126
- package/admin/src/pages/Roles/CreatePage/index.js +155 -147
- package/admin/src/pages/Roles/EditPage/index.js +162 -134
- package/admin/src/pages/Roles/ListPage/components/TableBody.js +96 -0
- package/admin/src/pages/Roles/ListPage/index.js +176 -156
- package/admin/src/pages/Roles/ListPage/utils/api.js +28 -0
- package/admin/src/pages/Roles/index.js +14 -8
- package/admin/src/translations/ar.json +0 -8
- package/admin/src/translations/cs.json +0 -8
- package/admin/src/translations/de.json +0 -8
- package/admin/src/translations/dk.json +0 -8
- package/admin/src/translations/en.json +33 -12
- package/admin/src/translations/es.json +0 -8
- package/admin/src/translations/fr.json +0 -8
- package/admin/src/translations/id.json +0 -8
- package/admin/src/translations/it.json +0 -8
- package/admin/src/translations/ja.json +0 -8
- package/admin/src/translations/ko.json +93 -54
- package/admin/src/translations/ms.json +0 -8
- package/admin/src/translations/nl.json +0 -8
- package/admin/src/translations/pl.json +0 -8
- package/admin/src/translations/pt-BR.json +0 -8
- package/admin/src/translations/pt.json +0 -8
- package/admin/src/translations/ru.json +0 -8
- package/admin/src/translations/sk.json +0 -8
- package/admin/src/translations/sv.json +0 -8
- package/admin/src/translations/th.json +0 -8
- package/admin/src/translations/tr.json +0 -8
- package/admin/src/translations/uk.json +0 -8
- package/admin/src/translations/vi.json +0 -8
- package/admin/src/translations/zh-Hans.json +5 -14
- package/admin/src/translations/zh.json +0 -8
- package/admin/src/utils/axiosInstance.js +36 -0
- package/admin/src/utils/formatPluginName.js +26 -0
- package/admin/src/utils/index.js +1 -0
- package/documentation/1.0.0/overrides/users-permissions-Role.json +6 -6
- package/documentation/1.0.0/overrides/users-permissions-User.json +7 -7
- package/jest.config.front.js +10 -0
- package/package.json +35 -32
- package/server/bootstrap/index.js +20 -25
- package/server/config.js +3 -3
- package/server/content-types/index.js +3 -3
- package/server/content-types/permission/index.js +30 -3
- package/server/content-types/role/index.js +47 -3
- package/server/content-types/user/index.js +65 -4
- package/server/controllers/auth.js +85 -237
- package/server/controllers/content-manager-user.js +183 -0
- package/server/controllers/index.js +12 -6
- package/server/controllers/permissions.js +26 -0
- package/server/controllers/role.js +77 -0
- package/server/controllers/settings.js +85 -0
- package/server/controllers/user.js +119 -45
- package/server/controllers/validation/auth.js +29 -0
- package/server/controllers/validation/user.js +38 -0
- package/server/graphql/index.js +44 -0
- package/server/graphql/mutations/auth/email-confirmation.js +39 -0
- package/server/graphql/mutations/auth/forgot-password.js +38 -0
- package/server/graphql/mutations/auth/login.js +38 -0
- package/server/graphql/mutations/auth/register.js +39 -0
- package/server/graphql/mutations/auth/reset-password.js +41 -0
- package/server/graphql/mutations/crud/role/create-role.js +37 -0
- package/server/graphql/mutations/crud/role/delete-role.js +28 -0
- package/server/graphql/mutations/crud/role/update-role.js +38 -0
- package/server/graphql/mutations/crud/user/create-user.js +48 -0
- package/server/graphql/mutations/crud/user/delete-user.js +42 -0
- package/server/graphql/mutations/crud/user/update-user.js +49 -0
- package/server/graphql/mutations/index.js +42 -0
- package/server/graphql/queries/index.js +13 -0
- package/server/graphql/queries/me.js +17 -0
- package/server/graphql/resolvers-configs.js +37 -0
- package/server/graphql/types/create-role-payload.js +11 -0
- package/server/graphql/types/delete-role-payload.js +11 -0
- package/server/graphql/types/index.js +21 -0
- package/server/graphql/types/login-input.js +13 -0
- package/server/graphql/types/login-payload.js +12 -0
- package/server/graphql/types/me-role.js +14 -0
- package/server/graphql/types/me.js +16 -0
- package/server/graphql/types/password-payload.js +11 -0
- package/server/graphql/types/register-input.js +13 -0
- package/server/graphql/types/update-role-payload.js +11 -0
- package/server/graphql/utils.js +27 -0
- package/server/index.js +21 -0
- package/server/middlewares/index.js +2 -2
- package/server/{policies → middlewares}/rateLimit.js +3 -7
- package/server/register.js +11 -0
- package/server/routes/admin/index.js +10 -0
- package/server/routes/admin/permissions.js +20 -0
- package/server/routes/admin/role.js +79 -0
- package/server/routes/admin/settings.js +95 -0
- package/server/routes/content-api/auth.js +73 -0
- package/server/routes/content-api/index.js +11 -0
- package/server/routes/content-api/permissions.js +9 -0
- package/server/routes/content-api/role.js +29 -0
- package/server/routes/content-api/user.js +61 -0
- package/server/routes/index.js +4 -3
- package/server/services/index.js +10 -8
- package/server/services/jwt.js +9 -17
- package/server/services/providers.js +32 -33
- package/server/services/role.js +177 -0
- package/server/services/user.js +9 -15
- package/server/services/users-permissions.js +140 -338
- package/server/strategies/users-permissions.js +123 -0
- package/server/utils/index.d.ts +2 -0
- package/strapi-admin.js +3 -0
- package/strapi-server.js +1 -19
- package/admin/src/assets/images/logo.svg +0 -1
- package/admin/src/components/BaselineAlignement/index.js +0 -33
- package/admin/src/components/Bloc/index.js +0 -10
- package/admin/src/components/BoundRoute/Components.js +0 -78
- package/admin/src/components/ContainerFluid/index.js +0 -13
- package/admin/src/components/FormBloc/index.js +0 -61
- package/admin/src/components/IntlInput/index.js +0 -38
- package/admin/src/components/ListBaselineAlignment/index.js +0 -8
- package/admin/src/components/ListRow/Components.js +0 -74
- package/admin/src/components/ListRow/index.js +0 -35
- package/admin/src/components/ModalForm/Wrapper.js +0 -12
- package/admin/src/components/ModalForm/index.js +0 -59
- package/admin/src/components/Permissions/ListWrapper.js +0 -9
- package/admin/src/components/Permissions/PermissionRow/BaselineAlignment.js +0 -7
- package/admin/src/components/Permissions/PermissionRow/RowStyle.js +0 -28
- package/admin/src/components/Permissions/PermissionRow/SubCategory/ConditionsButtonWrapper.js +0 -13
- package/admin/src/components/Permissions/PermissionRow/SubCategory/PolicyWrapper.js +0 -8
- package/admin/src/components/Permissions/PermissionRow/SubCategory/SubCategoryWrapper.js +0 -26
- package/admin/src/components/Permissions/PermissionRow/SubCategory/index.js +0 -116
- package/admin/src/components/Policies/Components.js +0 -26
- package/admin/src/components/PrefixedIcon/index.js +0 -27
- package/admin/src/components/Roles/EmptyRole/BaselineAlignment.js +0 -7
- package/admin/src/components/Roles/EmptyRole/index.js +0 -27
- package/admin/src/components/Roles/RoleListWrapper/index.js +0 -17
- package/admin/src/components/Roles/RoleRow/RoleDescription.js +0 -9
- package/admin/src/components/Roles/RoleRow/index.js +0 -45
- package/admin/src/components/Roles/index.js +0 -3
- package/admin/src/components/SizedInput/index.js +0 -24
- package/admin/src/pages/AdvancedSettings/reducer.js +0 -65
- package/admin/src/pages/AdvancedSettings/utils/form.js +0 -52
- package/admin/src/pages/EmailTemplates/CustomTextInput.js +0 -105
- package/admin/src/pages/EmailTemplates/Wrapper.js +0 -36
- package/admin/src/pages/EmailTemplates/reducer.js +0 -58
- package/admin/src/pages/EmailTemplates/utils/forms.js +0 -81
- package/admin/src/pages/Roles/ListPage/BaselineAlignment.js +0 -8
- package/server/content-types/permission/schema.json +0 -48
- package/server/content-types/role/schema.json +0 -46
- package/server/content-types/user/schema.json +0 -66
- package/server/controllers/user/admin.js +0 -230
- package/server/controllers/user/api.js +0 -174
- package/server/controllers/users-permissions.js +0 -271
- package/server/middlewares/users-permissions.js +0 -36
- package/server/policies/index.js +0 -11
- package/server/policies/isAuthenticated.js +0 -9
- package/server/policies/permissions.js +0 -94
- package/server/routes/routes.json +0 -381
- package/server/schema.graphql.js +0 -317
|
@@ -9,52 +9,39 @@
|
|
|
9
9
|
/* eslint-disable no-useless-escape */
|
|
10
10
|
const crypto = require('crypto');
|
|
11
11
|
const _ = require('lodash');
|
|
12
|
-
const
|
|
13
|
-
const { sanitizeEntity } = require('@strapi/utils');
|
|
12
|
+
const utils = require('@strapi/utils');
|
|
14
13
|
const { getService } = require('../utils');
|
|
14
|
+
const {
|
|
15
|
+
validateCallbackBody,
|
|
16
|
+
validateRegisterBody,
|
|
17
|
+
validateSendEmailConfirmationBody,
|
|
18
|
+
} = require('./validation/auth');
|
|
19
|
+
|
|
20
|
+
const { sanitize } = utils;
|
|
21
|
+
const { ApplicationError, ValidationError } = utils.errors;
|
|
15
22
|
|
|
16
23
|
const emailRegExp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
|
|
25
|
+
const sanitizeUser = (user, ctx) => {
|
|
26
|
+
const { auth } = ctx.state;
|
|
27
|
+
const userSchema = strapi.getModel('plugin::users-permissions.user');
|
|
28
|
+
|
|
29
|
+
return sanitize.contentAPI.output(user, userSchema, { auth });
|
|
30
|
+
};
|
|
20
31
|
|
|
21
32
|
module.exports = {
|
|
22
33
|
async callback(ctx) {
|
|
23
34
|
const provider = ctx.params.provider || 'local';
|
|
24
35
|
const params = ctx.request.body;
|
|
25
36
|
|
|
26
|
-
const store = await strapi.store({
|
|
27
|
-
environment: '',
|
|
28
|
-
type: 'plugin',
|
|
29
|
-
name: 'users-permissions',
|
|
30
|
-
});
|
|
37
|
+
const store = await strapi.store({ type: 'plugin', name: 'users-permissions' });
|
|
31
38
|
|
|
32
39
|
if (provider === 'local') {
|
|
33
40
|
if (!_.get(await store.get({ key: 'grant' }), 'email.enabled')) {
|
|
34
|
-
|
|
41
|
+
throw new ApplicationError('This provider is disabled');
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
if (!params.identifier) {
|
|
39
|
-
return ctx.badRequest(
|
|
40
|
-
null,
|
|
41
|
-
formatError({
|
|
42
|
-
id: 'Auth.form.error.email.provide',
|
|
43
|
-
message: 'Please provide your username or your e-mail.',
|
|
44
|
-
})
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// The password is required.
|
|
49
|
-
if (!params.password) {
|
|
50
|
-
return ctx.badRequest(
|
|
51
|
-
null,
|
|
52
|
-
formatError({
|
|
53
|
-
id: 'Auth.form.error.password.provide',
|
|
54
|
-
message: 'Please provide your password.',
|
|
55
|
-
})
|
|
56
|
-
);
|
|
57
|
-
}
|
|
44
|
+
await validateCallbackBody(params);
|
|
58
45
|
|
|
59
46
|
const query = { provider };
|
|
60
47
|
|
|
@@ -72,47 +59,24 @@ module.exports = {
|
|
|
72
59
|
const user = await strapi.query('plugin::users-permissions.user').findOne({ where: query });
|
|
73
60
|
|
|
74
61
|
if (!user) {
|
|
75
|
-
|
|
76
|
-
null,
|
|
77
|
-
formatError({
|
|
78
|
-
id: 'Auth.form.error.invalid',
|
|
79
|
-
message: 'Identifier or password invalid.',
|
|
80
|
-
})
|
|
81
|
-
);
|
|
62
|
+
throw new ValidationError('Invalid identifier or password');
|
|
82
63
|
}
|
|
83
64
|
|
|
84
65
|
if (
|
|
85
66
|
_.get(await store.get({ key: 'advanced' }), 'email_confirmation') &&
|
|
86
67
|
user.confirmed !== true
|
|
87
68
|
) {
|
|
88
|
-
|
|
89
|
-
null,
|
|
90
|
-
formatError({
|
|
91
|
-
id: 'Auth.form.error.confirmed',
|
|
92
|
-
message: 'Your account email is not confirmed',
|
|
93
|
-
})
|
|
94
|
-
);
|
|
69
|
+
throw new ApplicationError('Your account email is not confirmed');
|
|
95
70
|
}
|
|
96
71
|
|
|
97
72
|
if (user.blocked === true) {
|
|
98
|
-
|
|
99
|
-
null,
|
|
100
|
-
formatError({
|
|
101
|
-
id: 'Auth.form.error.blocked',
|
|
102
|
-
message: 'Your account has been blocked by an administrator',
|
|
103
|
-
})
|
|
104
|
-
);
|
|
73
|
+
throw new ApplicationError('Your account has been blocked by an administrator');
|
|
105
74
|
}
|
|
106
75
|
|
|
107
76
|
// The user never authenticated with the `local` provider.
|
|
108
77
|
if (!user.password) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
formatError({
|
|
112
|
-
id: 'Auth.form.error.password.local',
|
|
113
|
-
message:
|
|
114
|
-
'This user never set a local password, please login with the provider used during account creation.',
|
|
115
|
-
})
|
|
78
|
+
throw new ApplicationError(
|
|
79
|
+
'This user never set a local password, please login with the provider used during account creation'
|
|
116
80
|
);
|
|
117
81
|
}
|
|
118
82
|
|
|
@@ -122,32 +86,18 @@ module.exports = {
|
|
|
122
86
|
);
|
|
123
87
|
|
|
124
88
|
if (!validPassword) {
|
|
125
|
-
|
|
126
|
-
null,
|
|
127
|
-
formatError({
|
|
128
|
-
id: 'Auth.form.error.invalid',
|
|
129
|
-
message: 'Identifier or password invalid.',
|
|
130
|
-
})
|
|
131
|
-
);
|
|
89
|
+
throw new ValidationError('Invalid identifier or password');
|
|
132
90
|
} else {
|
|
133
91
|
ctx.send({
|
|
134
92
|
jwt: getService('jwt').issue({
|
|
135
93
|
id: user.id,
|
|
136
94
|
}),
|
|
137
|
-
user:
|
|
138
|
-
model: strapi.getModel('plugin::users-permissions.user'),
|
|
139
|
-
}),
|
|
95
|
+
user: await sanitizeUser(user, ctx),
|
|
140
96
|
});
|
|
141
97
|
}
|
|
142
98
|
} else {
|
|
143
99
|
if (!_.get(await store.get({ key: 'grant' }), [provider, 'enabled'])) {
|
|
144
|
-
|
|
145
|
-
null,
|
|
146
|
-
formatError({
|
|
147
|
-
id: 'provider.disabled',
|
|
148
|
-
message: 'This provider is disabled.',
|
|
149
|
-
})
|
|
150
|
-
);
|
|
100
|
+
throw new ApplicationError('This provider is disabled');
|
|
151
101
|
}
|
|
152
102
|
|
|
153
103
|
// Connect the user with the third-party provider.
|
|
@@ -156,18 +106,16 @@ module.exports = {
|
|
|
156
106
|
try {
|
|
157
107
|
[user, error] = await getService('providers').connect(provider, ctx.query);
|
|
158
108
|
} catch ([user, error]) {
|
|
159
|
-
|
|
109
|
+
throw new ApplicationError(error.message);
|
|
160
110
|
}
|
|
161
111
|
|
|
162
112
|
if (!user) {
|
|
163
|
-
|
|
113
|
+
throw new ApplicationError(error.message);
|
|
164
114
|
}
|
|
165
115
|
|
|
166
116
|
ctx.send({
|
|
167
117
|
jwt: getService('jwt').issue({ id: user.id }),
|
|
168
|
-
user:
|
|
169
|
-
model: strapi.getModel('plugin::users-permissions.user'),
|
|
170
|
-
}),
|
|
118
|
+
user: await sanitizeUser(user, ctx),
|
|
171
119
|
});
|
|
172
120
|
}
|
|
173
121
|
},
|
|
@@ -186,13 +134,7 @@ module.exports = {
|
|
|
186
134
|
.findOne({ where: { resetPasswordToken: `${params.code}` } });
|
|
187
135
|
|
|
188
136
|
if (!user) {
|
|
189
|
-
|
|
190
|
-
null,
|
|
191
|
-
formatError({
|
|
192
|
-
id: 'Auth.form.error.code.provide',
|
|
193
|
-
message: 'Incorrect code provided.',
|
|
194
|
-
})
|
|
195
|
-
);
|
|
137
|
+
throw new ValidationError('Incorrect code provided');
|
|
196
138
|
}
|
|
197
139
|
|
|
198
140
|
const password = await getService('user').hashPassword({ password: params.password });
|
|
@@ -204,53 +146,44 @@ module.exports = {
|
|
|
204
146
|
|
|
205
147
|
ctx.send({
|
|
206
148
|
jwt: getService('jwt').issue({ id: user.id }),
|
|
207
|
-
user:
|
|
208
|
-
model: strapi.getModel('plugin::users-permissions.user'),
|
|
209
|
-
}),
|
|
149
|
+
user: await sanitizeUser(user, ctx),
|
|
210
150
|
});
|
|
211
151
|
} else if (
|
|
212
152
|
params.password &&
|
|
213
153
|
params.passwordConfirmation &&
|
|
214
154
|
params.password !== params.passwordConfirmation
|
|
215
155
|
) {
|
|
216
|
-
|
|
217
|
-
null,
|
|
218
|
-
formatError({
|
|
219
|
-
id: 'Auth.form.error.password.matching',
|
|
220
|
-
message: 'Passwords do not match.',
|
|
221
|
-
})
|
|
222
|
-
);
|
|
156
|
+
throw new ValidationError('Passwords do not match');
|
|
223
157
|
} else {
|
|
224
|
-
|
|
225
|
-
null,
|
|
226
|
-
formatError({
|
|
227
|
-
id: 'Auth.form.error.params.provide',
|
|
228
|
-
message: 'Incorrect params provided.',
|
|
229
|
-
})
|
|
230
|
-
);
|
|
158
|
+
throw new ValidationError('Incorrect params provided');
|
|
231
159
|
}
|
|
232
160
|
},
|
|
233
161
|
|
|
234
162
|
async connect(ctx, next) {
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
name: 'users-permissions',
|
|
240
|
-
key: 'grant',
|
|
241
|
-
})
|
|
163
|
+
const grant = require('grant-koa');
|
|
164
|
+
|
|
165
|
+
const providers = await strapi
|
|
166
|
+
.store({ type: 'plugin', name: 'users-permissions', key: 'grant' })
|
|
242
167
|
.get();
|
|
243
168
|
|
|
169
|
+
const apiPrefix = strapi.config.get('api.rest.prefix');
|
|
170
|
+
const grantConfig = {
|
|
171
|
+
defaults: {
|
|
172
|
+
prefix: `${apiPrefix}/connect`,
|
|
173
|
+
},
|
|
174
|
+
...providers,
|
|
175
|
+
};
|
|
176
|
+
|
|
244
177
|
const [requestPath] = ctx.request.url.split('?');
|
|
245
|
-
const provider = requestPath.split('/')[
|
|
178
|
+
const provider = requestPath.split('/connect/')[1].split('/')[0];
|
|
246
179
|
|
|
247
180
|
if (!_.get(grantConfig[provider], 'enabled')) {
|
|
248
|
-
|
|
181
|
+
throw new ApplicationError('This provider is disabled');
|
|
249
182
|
}
|
|
250
183
|
|
|
251
184
|
if (!strapi.config.server.url.startsWith('http')) {
|
|
252
185
|
strapi.log.warn(
|
|
253
|
-
'You are using a third party provider for login. Make sure to set an absolute url in config/server.js. More info here: https://strapi.io/
|
|
186
|
+
'You are using a third party provider for login. Make sure to set an absolute url in config/server.js. More info here: https://docs.strapi.io/developer-docs/latest/plugins/users-permissions.html#setting-up-the-server-url'
|
|
254
187
|
);
|
|
255
188
|
}
|
|
256
189
|
|
|
@@ -270,20 +203,10 @@ module.exports = {
|
|
|
270
203
|
if (isEmail) {
|
|
271
204
|
email = email.toLowerCase();
|
|
272
205
|
} else {
|
|
273
|
-
|
|
274
|
-
null,
|
|
275
|
-
formatError({
|
|
276
|
-
id: 'Auth.form.error.email.format',
|
|
277
|
-
message: 'Please provide valid email address.',
|
|
278
|
-
})
|
|
279
|
-
);
|
|
206
|
+
throw new ValidationError('Please provide a valid email address');
|
|
280
207
|
}
|
|
281
208
|
|
|
282
|
-
const pluginStore = await strapi.store({
|
|
283
|
-
environment: '',
|
|
284
|
-
type: 'plugin',
|
|
285
|
-
name: 'users-permissions',
|
|
286
|
-
});
|
|
209
|
+
const pluginStore = await strapi.store({ type: 'plugin', name: 'users-permissions' });
|
|
287
210
|
|
|
288
211
|
// Find the user by email.
|
|
289
212
|
const user = await strapi
|
|
@@ -292,13 +215,12 @@ module.exports = {
|
|
|
292
215
|
|
|
293
216
|
// User not found.
|
|
294
217
|
if (!user) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
);
|
|
218
|
+
throw new ApplicationError('This email does not exist');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// User blocked
|
|
222
|
+
if (user.blocked) {
|
|
223
|
+
throw new ApplicationError('This user is disabled');
|
|
302
224
|
}
|
|
303
225
|
|
|
304
226
|
// Generate random token.
|
|
@@ -316,9 +238,7 @@ module.exports = {
|
|
|
316
238
|
key: 'advanced',
|
|
317
239
|
});
|
|
318
240
|
|
|
319
|
-
const userInfo =
|
|
320
|
-
model: strapi.getModel('plugin::users-permissions.user'),
|
|
321
|
-
});
|
|
241
|
+
const userInfo = await sanitizeUser(user, ctx);
|
|
322
242
|
|
|
323
243
|
settings.message = await getService('users-permissions').template(settings.message, {
|
|
324
244
|
URL: advanced.email_reset_password,
|
|
@@ -347,7 +267,7 @@ module.exports = {
|
|
|
347
267
|
html: settings.message,
|
|
348
268
|
});
|
|
349
269
|
} catch (err) {
|
|
350
|
-
|
|
270
|
+
throw new ApplicationError(err.message);
|
|
351
271
|
}
|
|
352
272
|
|
|
353
273
|
// Update the user.
|
|
@@ -359,24 +279,14 @@ module.exports = {
|
|
|
359
279
|
},
|
|
360
280
|
|
|
361
281
|
async register(ctx) {
|
|
362
|
-
const pluginStore = await strapi.store({
|
|
363
|
-
environment: '',
|
|
364
|
-
type: 'plugin',
|
|
365
|
-
name: 'users-permissions',
|
|
366
|
-
});
|
|
282
|
+
const pluginStore = await strapi.store({ type: 'plugin', name: 'users-permissions' });
|
|
367
283
|
|
|
368
284
|
const settings = await pluginStore.get({
|
|
369
285
|
key: 'advanced',
|
|
370
286
|
});
|
|
371
287
|
|
|
372
288
|
if (!settings.allow_register) {
|
|
373
|
-
|
|
374
|
-
null,
|
|
375
|
-
formatError({
|
|
376
|
-
id: 'Auth.advanced.allow_register',
|
|
377
|
-
message: 'Register action is currently disabled.',
|
|
378
|
-
})
|
|
379
|
-
);
|
|
289
|
+
throw new ApplicationError('Register action is currently disabled');
|
|
380
290
|
}
|
|
381
291
|
|
|
382
292
|
const params = {
|
|
@@ -384,37 +294,13 @@ module.exports = {
|
|
|
384
294
|
provider: 'local',
|
|
385
295
|
};
|
|
386
296
|
|
|
387
|
-
|
|
388
|
-
if (!params.password) {
|
|
389
|
-
return ctx.badRequest(
|
|
390
|
-
null,
|
|
391
|
-
formatError({
|
|
392
|
-
id: 'Auth.form.error.password.provide',
|
|
393
|
-
message: 'Please provide your password.',
|
|
394
|
-
})
|
|
395
|
-
);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// Email is required.
|
|
399
|
-
if (!params.email) {
|
|
400
|
-
return ctx.badRequest(
|
|
401
|
-
null,
|
|
402
|
-
formatError({
|
|
403
|
-
id: 'Auth.form.error.email.provide',
|
|
404
|
-
message: 'Please provide your email.',
|
|
405
|
-
})
|
|
406
|
-
);
|
|
407
|
-
}
|
|
297
|
+
await validateRegisterBody(params);
|
|
408
298
|
|
|
409
299
|
// Throw an error if the password selected by the user
|
|
410
300
|
// contains more than three times the symbol '$'.
|
|
411
301
|
if (getService('user').isHashed(params.password)) {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
formatError({
|
|
415
|
-
id: 'Auth.form.error.password.format',
|
|
416
|
-
message: 'Your password cannot contain more than three times the symbol `$`.',
|
|
417
|
-
})
|
|
302
|
+
throw new ValidationError(
|
|
303
|
+
'Your password cannot contain more than three times the symbol `$`'
|
|
418
304
|
);
|
|
419
305
|
}
|
|
420
306
|
|
|
@@ -423,13 +309,7 @@ module.exports = {
|
|
|
423
309
|
.findOne({ where: { type: settings.default_role } });
|
|
424
310
|
|
|
425
311
|
if (!role) {
|
|
426
|
-
|
|
427
|
-
null,
|
|
428
|
-
formatError({
|
|
429
|
-
id: 'Auth.form.error.role.notFound',
|
|
430
|
-
message: 'Impossible to find the default role.',
|
|
431
|
-
})
|
|
432
|
-
);
|
|
312
|
+
throw new ApplicationError('Impossible to find the default role');
|
|
433
313
|
}
|
|
434
314
|
|
|
435
315
|
// Check if the provided email is valid or not.
|
|
@@ -438,13 +318,7 @@ module.exports = {
|
|
|
438
318
|
if (isEmail) {
|
|
439
319
|
params.email = params.email.toLowerCase();
|
|
440
320
|
} else {
|
|
441
|
-
|
|
442
|
-
null,
|
|
443
|
-
formatError({
|
|
444
|
-
id: 'Auth.form.error.email.format',
|
|
445
|
-
message: 'Please provide valid email address.',
|
|
446
|
-
})
|
|
447
|
-
);
|
|
321
|
+
throw new ValidationError('Please provide a valid email address');
|
|
448
322
|
}
|
|
449
323
|
|
|
450
324
|
params.role = role.id;
|
|
@@ -455,23 +329,11 @@ module.exports = {
|
|
|
455
329
|
});
|
|
456
330
|
|
|
457
331
|
if (user && user.provider === params.provider) {
|
|
458
|
-
|
|
459
|
-
null,
|
|
460
|
-
formatError({
|
|
461
|
-
id: 'Auth.form.error.email.taken',
|
|
462
|
-
message: 'Email is already taken.',
|
|
463
|
-
})
|
|
464
|
-
);
|
|
332
|
+
throw new ApplicationError('Email is already taken');
|
|
465
333
|
}
|
|
466
334
|
|
|
467
335
|
if (user && user.provider !== params.provider && settings.unique_email) {
|
|
468
|
-
|
|
469
|
-
null,
|
|
470
|
-
formatError({
|
|
471
|
-
id: 'Auth.form.error.email.taken',
|
|
472
|
-
message: 'Email is already taken.',
|
|
473
|
-
})
|
|
474
|
-
);
|
|
336
|
+
throw new ApplicationError('Email is already taken');
|
|
475
337
|
}
|
|
476
338
|
|
|
477
339
|
try {
|
|
@@ -481,15 +343,13 @@ module.exports = {
|
|
|
481
343
|
|
|
482
344
|
const user = await strapi.query('plugin::users-permissions.user').create({ data: params });
|
|
483
345
|
|
|
484
|
-
const sanitizedUser =
|
|
485
|
-
model: strapi.getModel('plugin::users-permissions.user'),
|
|
486
|
-
});
|
|
346
|
+
const sanitizedUser = await sanitizeUser(user, ctx);
|
|
487
347
|
|
|
488
348
|
if (settings.email_confirmation) {
|
|
489
349
|
try {
|
|
490
|
-
await getService('user').sendConfirmationEmail(
|
|
350
|
+
await getService('user').sendConfirmationEmail(sanitizedUser);
|
|
491
351
|
} catch (err) {
|
|
492
|
-
|
|
352
|
+
throw new ApplicationError(err.message);
|
|
493
353
|
}
|
|
494
354
|
|
|
495
355
|
return ctx.send({ user: sanitizedUser });
|
|
@@ -502,14 +362,11 @@ module.exports = {
|
|
|
502
362
|
user: sanitizedUser,
|
|
503
363
|
});
|
|
504
364
|
} catch (err) {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
: { id: 'Auth.form.error.email.taken', message: 'Email already taken' };
|
|
511
|
-
|
|
512
|
-
ctx.badRequest(null, formatError(adminError));
|
|
365
|
+
if (_.includes(err.message, 'username')) {
|
|
366
|
+
throw new ApplicationError('Username already taken');
|
|
367
|
+
} else {
|
|
368
|
+
throw new ApplicationError('Email already taken');
|
|
369
|
+
}
|
|
513
370
|
}
|
|
514
371
|
},
|
|
515
372
|
|
|
@@ -520,13 +377,13 @@ module.exports = {
|
|
|
520
377
|
const jwtService = getService('jwt');
|
|
521
378
|
|
|
522
379
|
if (_.isEmpty(confirmationToken)) {
|
|
523
|
-
|
|
380
|
+
throw new ValidationError('token.invalid');
|
|
524
381
|
}
|
|
525
382
|
|
|
526
383
|
const user = await userService.fetch({ confirmationToken }, []);
|
|
527
384
|
|
|
528
385
|
if (!user) {
|
|
529
|
-
|
|
386
|
+
throw new ValidationError('token.invalid');
|
|
530
387
|
}
|
|
531
388
|
|
|
532
389
|
await userService.edit({ id: user.id }, { confirmed: true, confirmationToken: null });
|
|
@@ -534,18 +391,11 @@ module.exports = {
|
|
|
534
391
|
if (returnUser) {
|
|
535
392
|
ctx.send({
|
|
536
393
|
jwt: jwtService.issue({ id: user.id }),
|
|
537
|
-
user:
|
|
538
|
-
model: strapi.getModel('plugin::users-permissions.user'),
|
|
539
|
-
}),
|
|
394
|
+
user: await sanitizeUser(user, ctx),
|
|
540
395
|
});
|
|
541
396
|
} else {
|
|
542
397
|
const settings = await strapi
|
|
543
|
-
.store({
|
|
544
|
-
environment: '',
|
|
545
|
-
type: 'plugin',
|
|
546
|
-
name: 'users-permissions',
|
|
547
|
-
key: 'advanced',
|
|
548
|
-
})
|
|
398
|
+
.store({ type: 'plugin', name: 'users-permissions', key: 'advanced' })
|
|
549
399
|
.get();
|
|
550
400
|
|
|
551
401
|
ctx.redirect(settings.email_confirmation_redirection || '/');
|
|
@@ -555,16 +405,14 @@ module.exports = {
|
|
|
555
405
|
async sendEmailConfirmation(ctx) {
|
|
556
406
|
const params = _.assign(ctx.request.body);
|
|
557
407
|
|
|
558
|
-
|
|
559
|
-
return ctx.badRequest('missing.email');
|
|
560
|
-
}
|
|
408
|
+
await validateSendEmailConfirmationBody(params);
|
|
561
409
|
|
|
562
410
|
const isEmail = emailRegExp.test(params.email);
|
|
563
411
|
|
|
564
412
|
if (isEmail) {
|
|
565
413
|
params.email = params.email.toLowerCase();
|
|
566
414
|
} else {
|
|
567
|
-
|
|
415
|
+
throw new ValidationError('wrong.email');
|
|
568
416
|
}
|
|
569
417
|
|
|
570
418
|
const user = await strapi.query('plugin::users-permissions.user').findOne({
|
|
@@ -572,11 +420,11 @@ module.exports = {
|
|
|
572
420
|
});
|
|
573
421
|
|
|
574
422
|
if (user.confirmed) {
|
|
575
|
-
|
|
423
|
+
throw new ApplicationError('already.confirmed');
|
|
576
424
|
}
|
|
577
425
|
|
|
578
426
|
if (user.blocked) {
|
|
579
|
-
|
|
427
|
+
throw new ApplicationError('blocked.user');
|
|
580
428
|
}
|
|
581
429
|
|
|
582
430
|
try {
|
|
@@ -586,7 +434,7 @@ module.exports = {
|
|
|
586
434
|
sent: true,
|
|
587
435
|
});
|
|
588
436
|
} catch (err) {
|
|
589
|
-
|
|
437
|
+
throw new ApplicationError(err.message);
|
|
590
438
|
}
|
|
591
439
|
},
|
|
592
440
|
};
|