@strapi/plugin-users-permissions 4.0.0-next.9 → 4.0.0
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 +0 -8
- package/admin/src/pages/AdvancedSettings/index.js +203 -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 +22 -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 +117 -197
- package/admin/src/pages/EmailTemplates/utils/api.js +13 -0
- package/admin/src/pages/Providers/index.js +206 -221
- 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/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 +0 -8
- 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/package.json +30 -31
- package/server/bootstrap/index.js +19 -21
- 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 +81 -244
- 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 +118 -44
- 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 -428
- 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 -44
- package/server/policies/index.js +0 -11
- package/server/policies/isAuthenticated.js +0 -9
- package/server/policies/permissions.js +0 -94
- 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 a 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,24 +215,12 @@ module.exports = {
|
|
|
292
215
|
|
|
293
216
|
// User not found.
|
|
294
217
|
if (!user) {
|
|
295
|
-
|
|
296
|
-
null,
|
|
297
|
-
formatError({
|
|
298
|
-
id: 'Auth.form.error.user.not-exist',
|
|
299
|
-
message: 'This email does not exist.',
|
|
300
|
-
})
|
|
301
|
-
);
|
|
218
|
+
throw new ApplicationError('This email does not exist');
|
|
302
219
|
}
|
|
303
220
|
|
|
304
221
|
// User blocked
|
|
305
222
|
if (user.blocked) {
|
|
306
|
-
|
|
307
|
-
null,
|
|
308
|
-
formatError({
|
|
309
|
-
id: 'Auth.form.error.user.blocked',
|
|
310
|
-
message: 'This user is disabled.',
|
|
311
|
-
})
|
|
312
|
-
);
|
|
223
|
+
throw new ApplicationError('This user is disabled');
|
|
313
224
|
}
|
|
314
225
|
|
|
315
226
|
// Generate random token.
|
|
@@ -327,9 +238,7 @@ module.exports = {
|
|
|
327
238
|
key: 'advanced',
|
|
328
239
|
});
|
|
329
240
|
|
|
330
|
-
const userInfo =
|
|
331
|
-
model: strapi.getModel('plugin::users-permissions.user'),
|
|
332
|
-
});
|
|
241
|
+
const userInfo = await sanitizeUser(user, ctx);
|
|
333
242
|
|
|
334
243
|
settings.message = await getService('users-permissions').template(settings.message, {
|
|
335
244
|
URL: advanced.email_reset_password,
|
|
@@ -358,7 +267,7 @@ module.exports = {
|
|
|
358
267
|
html: settings.message,
|
|
359
268
|
});
|
|
360
269
|
} catch (err) {
|
|
361
|
-
|
|
270
|
+
throw new ApplicationError(err.message);
|
|
362
271
|
}
|
|
363
272
|
|
|
364
273
|
// Update the user.
|
|
@@ -370,24 +279,14 @@ module.exports = {
|
|
|
370
279
|
},
|
|
371
280
|
|
|
372
281
|
async register(ctx) {
|
|
373
|
-
const pluginStore = await strapi.store({
|
|
374
|
-
environment: '',
|
|
375
|
-
type: 'plugin',
|
|
376
|
-
name: 'users-permissions',
|
|
377
|
-
});
|
|
282
|
+
const pluginStore = await strapi.store({ type: 'plugin', name: 'users-permissions' });
|
|
378
283
|
|
|
379
284
|
const settings = await pluginStore.get({
|
|
380
285
|
key: 'advanced',
|
|
381
286
|
});
|
|
382
287
|
|
|
383
288
|
if (!settings.allow_register) {
|
|
384
|
-
|
|
385
|
-
null,
|
|
386
|
-
formatError({
|
|
387
|
-
id: 'Auth.advanced.allow_register',
|
|
388
|
-
message: 'Register action is currently disabled.',
|
|
389
|
-
})
|
|
390
|
-
);
|
|
289
|
+
throw new ApplicationError('Register action is currently disabled');
|
|
391
290
|
}
|
|
392
291
|
|
|
393
292
|
const params = {
|
|
@@ -395,37 +294,13 @@ module.exports = {
|
|
|
395
294
|
provider: 'local',
|
|
396
295
|
};
|
|
397
296
|
|
|
398
|
-
|
|
399
|
-
if (!params.password) {
|
|
400
|
-
return ctx.badRequest(
|
|
401
|
-
null,
|
|
402
|
-
formatError({
|
|
403
|
-
id: 'Auth.form.error.password.provide',
|
|
404
|
-
message: 'Please provide your password.',
|
|
405
|
-
})
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
// Email is required.
|
|
410
|
-
if (!params.email) {
|
|
411
|
-
return ctx.badRequest(
|
|
412
|
-
null,
|
|
413
|
-
formatError({
|
|
414
|
-
id: 'Auth.form.error.email.provide',
|
|
415
|
-
message: 'Please provide your email.',
|
|
416
|
-
})
|
|
417
|
-
);
|
|
418
|
-
}
|
|
297
|
+
await validateRegisterBody(params);
|
|
419
298
|
|
|
420
299
|
// Throw an error if the password selected by the user
|
|
421
300
|
// contains more than three times the symbol '$'.
|
|
422
301
|
if (getService('user').isHashed(params.password)) {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
formatError({
|
|
426
|
-
id: 'Auth.form.error.password.format',
|
|
427
|
-
message: 'Your password cannot contain more than three times the symbol `$`.',
|
|
428
|
-
})
|
|
302
|
+
throw new ValidationError(
|
|
303
|
+
'Your password cannot contain more than three times the symbol `$`'
|
|
429
304
|
);
|
|
430
305
|
}
|
|
431
306
|
|
|
@@ -434,13 +309,7 @@ module.exports = {
|
|
|
434
309
|
.findOne({ where: { type: settings.default_role } });
|
|
435
310
|
|
|
436
311
|
if (!role) {
|
|
437
|
-
|
|
438
|
-
null,
|
|
439
|
-
formatError({
|
|
440
|
-
id: 'Auth.form.error.role.notFound',
|
|
441
|
-
message: 'Impossible to find the default role.',
|
|
442
|
-
})
|
|
443
|
-
);
|
|
312
|
+
throw new ApplicationError('Impossible to find the default role');
|
|
444
313
|
}
|
|
445
314
|
|
|
446
315
|
// Check if the provided email is valid or not.
|
|
@@ -449,13 +318,7 @@ module.exports = {
|
|
|
449
318
|
if (isEmail) {
|
|
450
319
|
params.email = params.email.toLowerCase();
|
|
451
320
|
} else {
|
|
452
|
-
|
|
453
|
-
null,
|
|
454
|
-
formatError({
|
|
455
|
-
id: 'Auth.form.error.email.format',
|
|
456
|
-
message: 'Please provide valid email address.',
|
|
457
|
-
})
|
|
458
|
-
);
|
|
321
|
+
throw new ValidationError('Please provide a valid email address');
|
|
459
322
|
}
|
|
460
323
|
|
|
461
324
|
params.role = role.id;
|
|
@@ -466,23 +329,11 @@ module.exports = {
|
|
|
466
329
|
});
|
|
467
330
|
|
|
468
331
|
if (user && user.provider === params.provider) {
|
|
469
|
-
|
|
470
|
-
null,
|
|
471
|
-
formatError({
|
|
472
|
-
id: 'Auth.form.error.email.taken',
|
|
473
|
-
message: 'Email is already taken.',
|
|
474
|
-
})
|
|
475
|
-
);
|
|
332
|
+
throw new ApplicationError('Email is already taken');
|
|
476
333
|
}
|
|
477
334
|
|
|
478
335
|
if (user && user.provider !== params.provider && settings.unique_email) {
|
|
479
|
-
|
|
480
|
-
null,
|
|
481
|
-
formatError({
|
|
482
|
-
id: 'Auth.form.error.email.taken',
|
|
483
|
-
message: 'Email is already taken.',
|
|
484
|
-
})
|
|
485
|
-
);
|
|
336
|
+
throw new ApplicationError('Email is already taken');
|
|
486
337
|
}
|
|
487
338
|
|
|
488
339
|
try {
|
|
@@ -492,15 +343,13 @@ module.exports = {
|
|
|
492
343
|
|
|
493
344
|
const user = await strapi.query('plugin::users-permissions.user').create({ data: params });
|
|
494
345
|
|
|
495
|
-
const sanitizedUser =
|
|
496
|
-
model: strapi.getModel('plugin::users-permissions.user'),
|
|
497
|
-
});
|
|
346
|
+
const sanitizedUser = await sanitizeUser(user, ctx);
|
|
498
347
|
|
|
499
348
|
if (settings.email_confirmation) {
|
|
500
349
|
try {
|
|
501
|
-
await getService('user').sendConfirmationEmail(
|
|
350
|
+
await getService('user').sendConfirmationEmail(sanitizedUser);
|
|
502
351
|
} catch (err) {
|
|
503
|
-
|
|
352
|
+
throw new ApplicationError(err.message);
|
|
504
353
|
}
|
|
505
354
|
|
|
506
355
|
return ctx.send({ user: sanitizedUser });
|
|
@@ -513,14 +362,11 @@ module.exports = {
|
|
|
513
362
|
user: sanitizedUser,
|
|
514
363
|
});
|
|
515
364
|
} catch (err) {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
: { id: 'Auth.form.error.email.taken', message: 'Email already taken' };
|
|
522
|
-
|
|
523
|
-
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
|
+
}
|
|
524
370
|
}
|
|
525
371
|
},
|
|
526
372
|
|
|
@@ -531,13 +377,13 @@ module.exports = {
|
|
|
531
377
|
const jwtService = getService('jwt');
|
|
532
378
|
|
|
533
379
|
if (_.isEmpty(confirmationToken)) {
|
|
534
|
-
|
|
380
|
+
throw new ValidationError('token.invalid');
|
|
535
381
|
}
|
|
536
382
|
|
|
537
383
|
const user = await userService.fetch({ confirmationToken }, []);
|
|
538
384
|
|
|
539
385
|
if (!user) {
|
|
540
|
-
|
|
386
|
+
throw new ValidationError('token.invalid');
|
|
541
387
|
}
|
|
542
388
|
|
|
543
389
|
await userService.edit({ id: user.id }, { confirmed: true, confirmationToken: null });
|
|
@@ -545,18 +391,11 @@ module.exports = {
|
|
|
545
391
|
if (returnUser) {
|
|
546
392
|
ctx.send({
|
|
547
393
|
jwt: jwtService.issue({ id: user.id }),
|
|
548
|
-
user:
|
|
549
|
-
model: strapi.getModel('plugin::users-permissions.user'),
|
|
550
|
-
}),
|
|
394
|
+
user: await sanitizeUser(user, ctx),
|
|
551
395
|
});
|
|
552
396
|
} else {
|
|
553
397
|
const settings = await strapi
|
|
554
|
-
.store({
|
|
555
|
-
environment: '',
|
|
556
|
-
type: 'plugin',
|
|
557
|
-
name: 'users-permissions',
|
|
558
|
-
key: 'advanced',
|
|
559
|
-
})
|
|
398
|
+
.store({ type: 'plugin', name: 'users-permissions', key: 'advanced' })
|
|
560
399
|
.get();
|
|
561
400
|
|
|
562
401
|
ctx.redirect(settings.email_confirmation_redirection || '/');
|
|
@@ -566,16 +405,14 @@ module.exports = {
|
|
|
566
405
|
async sendEmailConfirmation(ctx) {
|
|
567
406
|
const params = _.assign(ctx.request.body);
|
|
568
407
|
|
|
569
|
-
|
|
570
|
-
return ctx.badRequest('missing.email');
|
|
571
|
-
}
|
|
408
|
+
await validateSendEmailConfirmationBody(params);
|
|
572
409
|
|
|
573
410
|
const isEmail = emailRegExp.test(params.email);
|
|
574
411
|
|
|
575
412
|
if (isEmail) {
|
|
576
413
|
params.email = params.email.toLowerCase();
|
|
577
414
|
} else {
|
|
578
|
-
|
|
415
|
+
throw new ValidationError('wrong.email');
|
|
579
416
|
}
|
|
580
417
|
|
|
581
418
|
const user = await strapi.query('plugin::users-permissions.user').findOne({
|
|
@@ -583,11 +420,11 @@ module.exports = {
|
|
|
583
420
|
});
|
|
584
421
|
|
|
585
422
|
if (user.confirmed) {
|
|
586
|
-
|
|
423
|
+
throw new ApplicationError('already.confirmed');
|
|
587
424
|
}
|
|
588
425
|
|
|
589
426
|
if (user.blocked) {
|
|
590
|
-
|
|
427
|
+
throw new ApplicationError('blocked.user');
|
|
591
428
|
}
|
|
592
429
|
|
|
593
430
|
try {
|
|
@@ -597,7 +434,7 @@ module.exports = {
|
|
|
597
434
|
sent: true,
|
|
598
435
|
});
|
|
599
436
|
} catch (err) {
|
|
600
|
-
|
|
437
|
+
throw new ApplicationError(err.message);
|
|
601
438
|
}
|
|
602
439
|
},
|
|
603
440
|
};
|