@shun-js/user 0.4.1 → 0.4.3

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": "@shun-js/user",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "user",
5
5
  "keywords": [
6
6
  "shun.js",
@@ -34,5 +34,5 @@
34
34
  "access": "public",
35
35
  "registry": "https://registry.npmjs.org/"
36
36
  },
37
- "gitHead": "3c64e232fe2242f4306dd9ce1102c70f00acf75d"
37
+ "gitHead": "03c6078d94915e4535031dbd04e507b21b6aa517"
38
38
  }
@@ -1,6 +1,9 @@
1
1
  // model
2
2
  const { getUserInfoById } = require('../model/UserInfoModel.js');
3
3
 
4
+ // util
5
+ const { getUserAccessToken } = require('../util/user.js');
6
+
4
7
  /**
5
8
  * userInfo
6
9
  * @param {*} req
@@ -23,6 +26,10 @@ exports.userInfo = async (req, res) => {
23
26
  const getUserInfoByIdRes = await getUserInfoById(req, res, userid);
24
27
  if (!getUserInfoByIdRes) return;
25
28
 
29
+ // access token
30
+ const accessToken = await getUserAccessToken(req, userid);
31
+ getUserInfoByIdRes.accessToken = accessToken;
32
+
26
33
  // r
27
34
  res.jsonSuccess('登录成功!', getUserInfoByIdRes);
28
35
  };
@@ -4,7 +4,7 @@ select
4
4
  from
5
5
  t_user_info
6
6
  where
7
- user_item_id=1
7
+ user_item_id=?
8
8
  and
9
9
  del_tag='0'
10
10
  `;
@@ -1,5 +1,5 @@
1
1
  // qiao
2
- const { AESEncrypt } = require('qiao-encode');
2
+ const { AESEncrypt, uuid } = require('qiao-encode');
3
3
 
4
4
  // model
5
5
  const { getUserItemByName, addUserItem } = require('../model/UserItemModel.js');
@@ -60,3 +60,21 @@ exports.loginORRegUser = async (req, res, mobileOREmail) => {
60
60
  // r
61
61
  return userItem;
62
62
  };
63
+
64
+ /**
65
+ * getUserAccessToken
66
+ * @param {*} req
67
+ * @param {*} userid
68
+ * @returns
69
+ */
70
+ exports.getUserAccessToken = async (req, userid) => {
71
+ // get
72
+ const acKey = `ac-${userid}`;
73
+ const accessToken = await req.redis.get(acKey);
74
+ if (accessToken) return accessToken;
75
+
76
+ // set
77
+ const newAccessToken = uuid();
78
+ await req.redis.set(acKey, newAccessToken);
79
+ return newAccessToken;
80
+ };