@strapi/plugin-users-permissions 5.0.0-beta.4 → 5.0.0-beta.5

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.
Files changed (28) hide show
  1. package/dist/_chunks/{index-i37IN_fH-BF_n1AVy.mjs → index-3MYZ88xc-BF_n1AVy.mjs} +1 -1
  2. package/dist/_chunks/{index-i37IN_fH-BF_n1AVy.mjs.map → index-3MYZ88xc-BF_n1AVy.mjs.map} +1 -1
  3. package/dist/_chunks/{index-i37IN_fH-_tlNeVkL.js → index-3MYZ88xc-_tlNeVkL.js} +1 -1
  4. package/dist/_chunks/{index-i37IN_fH-_tlNeVkL.js.map → index-3MYZ88xc-_tlNeVkL.js.map} +1 -1
  5. package/dist/_chunks/{index-Doewayrm.mjs → index-BTq-ZJe4.mjs} +10 -10
  6. package/dist/_chunks/{index-Doewayrm.mjs.map → index-BTq-ZJe4.mjs.map} +1 -1
  7. package/dist/_chunks/{index-BQQx9fm3.js → index-BcVrVSWh.js} +2 -2
  8. package/dist/_chunks/{index-BQQx9fm3.js.map → index-BcVrVSWh.js.map} +1 -1
  9. package/dist/_chunks/{index-N9_Qd-tg.mjs → index-BnYxQhNf.mjs} +3 -3
  10. package/dist/_chunks/{index-N9_Qd-tg.mjs.map → index-BnYxQhNf.mjs.map} +1 -1
  11. package/dist/_chunks/{index-7wfWos1T.js → index-BqRcQLbX.js} +10 -10
  12. package/dist/_chunks/{index-7wfWos1T.js.map → index-BqRcQLbX.js.map} +1 -1
  13. package/dist/_chunks/{index-Cgtj8fbz.js → index-CKKnf-Tb.js} +4 -4
  14. package/dist/_chunks/{index-Cgtj8fbz.js.map → index-CKKnf-Tb.js.map} +1 -1
  15. package/dist/_chunks/{index-l2QT_IDT.js → index-CiXGPtL-.js} +2 -2
  16. package/dist/_chunks/{index-l2QT_IDT.js.map → index-CiXGPtL-.js.map} +1 -1
  17. package/dist/_chunks/{index-BPGl32Qx.mjs → index-DnKoxcjm.mjs} +2 -2
  18. package/dist/_chunks/{index-BPGl32Qx.mjs.map → index-DnKoxcjm.mjs.map} +1 -1
  19. package/dist/_chunks/{index-vs42H81V.mjs → index-DsMCh6W5.mjs} +3 -3
  20. package/dist/_chunks/{index-vs42H81V.mjs.map → index-DsMCh6W5.mjs.map} +1 -1
  21. package/dist/_chunks/{index-DR9uuqpY.mjs → index-DsumUSPh.mjs} +2 -2
  22. package/dist/_chunks/{index-DR9uuqpY.mjs.map → index-DsumUSPh.mjs.map} +1 -1
  23. package/dist/_chunks/{index-BzscZzdb.js → index-cSq8h4Av.js} +4 -4
  24. package/dist/_chunks/{index-BzscZzdb.js.map → index-cSq8h4Av.js.map} +1 -1
  25. package/dist/admin/index.js +1 -1
  26. package/dist/admin/index.mjs +1 -1
  27. package/package.json +6 -6
  28. package/server/services/user.js +21 -4
@@ -11,6 +11,7 @@ const bcrypt = require('bcryptjs');
11
11
  const urlJoin = require('url-join');
12
12
 
13
13
  const { sanitize } = require('@strapi/utils');
14
+ const { toNumber, getOr } = require('lodash/fp');
14
15
  const { getService } = require('../utils');
15
16
 
16
17
  const USER_MODEL_UID = 'plugin::users-permissions.user';
@@ -27,10 +28,26 @@ module.exports = ({ strapi }) => ({
27
28
  },
28
29
 
29
30
  /**
30
- * Promise to search count users
31
+ * Hashes password fields in the provided values object if they are present.
32
+ * It checks each key in the values object against the model's attributes and
33
+ * hashes it if the attribute type is 'password',
31
34
  *
32
- * @return {Promise}
35
+ * @param {object} values - The object containing the fields to be hashed.
36
+ * @return {object} The values object with hashed password fields if they were present.
33
37
  */
38
+ async ensureHashedPasswords(values) {
39
+ const attributes = strapi.getModel(USER_MODEL_UID).attributes;
40
+
41
+ for (const key in values) {
42
+ if (attributes[key] && attributes[key].type === 'password') {
43
+ // Check if a custom encryption.rounds has been set on the password attribute
44
+ const rounds = toNumber(getOr(10, 'encryption.rounds', attributes[key]));
45
+ values[key] = await bcrypt.hash(values[key], rounds);
46
+ }
47
+ }
48
+
49
+ return values;
50
+ },
34
51
 
35
52
  /**
36
53
  * Promise to add a/an user.
@@ -38,7 +55,7 @@ module.exports = ({ strapi }) => ({
38
55
  */
39
56
  async add(values) {
40
57
  return strapi.db.query(USER_MODEL_UID).create({
41
- data: values,
58
+ data: await this.ensureHashedPasswords(values),
42
59
  populate: ['role'],
43
60
  });
44
61
  },
@@ -52,7 +69,7 @@ module.exports = ({ strapi }) => ({
52
69
  async edit(userId, params = {}) {
53
70
  return strapi.db.query(USER_MODEL_UID).update({
54
71
  where: { id: userId },
55
- data: params,
72
+ data: await this.ensureHashedPasswords(params),
56
73
  populate: ['role'],
57
74
  });
58
75
  },