@strapi/plugin-users-permissions 4.0.6 → 4.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/plugin-users-permissions",
3
- "version": "4.0.6",
3
+ "version": "4.0.7",
4
4
  "description": "Protect your API with a full-authentication process based on JWT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,8 +28,8 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@purest/providers": "^1.0.2",
31
- "@strapi/helper-plugin": "4.0.6",
32
- "@strapi/utils": "4.0.6",
31
+ "@strapi/helper-plugin": "4.0.7",
32
+ "@strapi/utils": "4.0.7",
33
33
  "bcryptjs": "2.4.3",
34
34
  "grant-koa": "5.4.8",
35
35
  "jsonwebtoken": "^8.1.0",
@@ -61,5 +61,5 @@
61
61
  "required": true,
62
62
  "kind": "plugin"
63
63
  },
64
- "gitHead": "5b48053946aacfb564ff423342fe70d79cd6d66d"
64
+ "gitHead": "af0cba8c5b2ba7b371523e8f55413ef0fce98e1e"
65
65
  }
@@ -137,13 +137,8 @@ module.exports = {
137
137
  throw new ValidationError('Incorrect code provided');
138
138
  }
139
139
 
140
- const password = await getService('user').hashPassword({ password: params.password });
141
-
140
+ await getService('user').edit(user.id, { resetPasswordToken: null, password: params.password });
142
141
  // Update the user.
143
- await strapi
144
- .query('plugin::users-permissions.user')
145
- .update({ where: { id: user.id }, data: { resetPasswordToken: null, password } });
146
-
147
142
  ctx.send({
148
143
  jwt: getService('jwt').issue({ id: user.id }),
149
144
  user: await sanitizeUser(user, ctx),
@@ -325,7 +320,6 @@ module.exports = {
325
320
  }
326
321
 
327
322
  params.role = role.id;
328
- params.password = await getService('user').hashPassword(params);
329
323
 
330
324
  const user = await strapi.query('plugin::users-permissions.user').findOne({
331
325
  where: { email: params.email },
@@ -344,7 +338,7 @@ module.exports = {
344
338
  params.confirmed = true;
345
339
  }
346
340
 
347
- const user = await strapi.query('plugin::users-permissions.user').create({ data: params });
341
+ const user = await getService('user').add(params);
348
342
 
349
343
  const sanitizedUser = await sanitizeUser(user, ctx);
350
344
 
@@ -367,8 +361,11 @@ module.exports = {
367
361
  } catch (err) {
368
362
  if (_.includes(err.message, 'username')) {
369
363
  throw new ApplicationError('Username already taken');
370
- } else {
364
+ } else if (_.includes(err.message, 'email')) {
371
365
  throw new ApplicationError('Email already taken');
366
+ } else {
367
+ strapi.log.error(err);
368
+ throw new ApplicationError('An error occurred during account creation');
372
369
  }
373
370
  }
374
371
  },
@@ -35,13 +35,10 @@ module.exports = ({ strapi }) => ({
35
35
  * @return {Promise}
36
36
  */
37
37
  async add(values) {
38
- if (values.password) {
39
- values.password = await getService('user').hashPassword(values);
40
- }
41
-
42
- return strapi
43
- .query('plugin::users-permissions.user')
44
- .create({ data: values, populate: ['role'] });
38
+ return strapi.entityService.create('plugin::users-permissions.user', {
39
+ data: values,
40
+ populate: ['role'],
41
+ });
45
42
  },
46
43
 
47
44
  /**
@@ -51,10 +48,6 @@ module.exports = ({ strapi }) => ({
51
48
  * @return {Promise}
52
49
  */
53
50
  async edit(userId, params = {}) {
54
- if (params.password) {
55
- params.password = await getService('user').hashPassword(params);
56
- }
57
-
58
51
  return strapi.entityService.update('plugin::users-permissions.user', userId, {
59
52
  data: params,
60
53
  populate: ['role'],
@@ -87,21 +80,13 @@ module.exports = ({ strapi }) => ({
87
80
  return strapi.query('plugin::users-permissions.user').findMany({ where: params, populate });
88
81
  },
89
82
 
90
- hashPassword(user = {}) {
91
- return new Promise((resolve, reject) => {
92
- if (!user.password || this.isHashed(user.password)) {
93
- resolve(null);
94
- } else {
95
- bcrypt.hash(`${user.password}`, 10, (err, hash) => {
96
- if (err) {
97
- return reject(err);
98
- }
99
- resolve(hash);
100
- });
101
- }
102
- });
83
+ /**
84
+ * Promise to remove a/an user.
85
+ * @return {Promise}
86
+ */
87
+ async remove(params) {
88
+ return strapi.query('plugin::users-permissions.user').delete({ where: params });
103
89
  },
104
-
105
90
  isHashed(password) {
106
91
  if (typeof password !== 'string' || !password) {
107
92
  return false;
@@ -110,14 +95,6 @@ module.exports = ({ strapi }) => ({
110
95
  return password.split('$').length === 4;
111
96
  },
112
97
 
113
- /**
114
- * Promise to remove a/an user.
115
- * @return {Promise}
116
- */
117
- async remove(params) {
118
- return strapi.query('plugin::users-permissions.user').delete({ where: params });
119
- },
120
-
121
98
  validatePassword(password, hash) {
122
99
  return bcrypt.compare(password, hash);
123
100
  },