mdkcontroller 1.4.15 → 1.4.17

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.
@@ -23,7 +23,38 @@ export default function () {
23
23
  return null;
24
24
  }
25
25
  }
26
- const validateBase = function name(req, res) {
26
+ const validateBaseByToken = function (accessToken) {
27
+ const db = global.db;
28
+ const tbUser = db.data.users;
29
+
30
+ if (accessToken) {
31
+ const jwtValidate = hideverifyJWT(accessToken);
32
+ if (!jwtValidate) {
33
+ return -1;
34
+ }
35
+ const userName = jwtValidate.username;
36
+ if (!userName) {
37
+ return -1;
38
+ }
39
+
40
+ let userO = userCache.get(userName);
41
+
42
+ if (!userO) {
43
+ userO = tbUser.find(f => f.username === userName);
44
+ if (!userO) return -1;
45
+
46
+ userCache.set(userName, userO);
47
+ }
48
+ if (userO.signcode != jwtValidate.signcode) {
49
+ return -1;
50
+ }
51
+
52
+ return 1;
53
+ } else {
54
+ return 0;
55
+ }
56
+ }
57
+ const validateBase = function (req, res) {
27
58
  const db = global.db;
28
59
  const tbUser = db.data.users;
29
60
 
@@ -76,7 +107,16 @@ export default function () {
76
107
  }
77
108
  },
78
109
  validateBool: (req, res) => {
79
- return validateBase(req, res);
110
+ const rs = validateBase(req, res);
111
+ if (rs != 1) {
112
+ res.clearCookie('access_token', { httpOnly: true });
113
+ res.clearCookie('sessionUExt', {});
114
+ res.clearCookie('username', {});
115
+ }
116
+ return rs;
117
+ },
118
+ validateByToken: (accessToken) => {
119
+ return validateBaseByToken(accessToken);
80
120
  },
81
121
  encrypt: function (data = "", pw = "mdkpaswoEcrHidDefat") {
82
122
  return encrypt(data, pw);
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "node-cache": "^5.1.2"
9
9
  },
10
10
  "name": "mdkcontroller",
11
- "version": "1.4.15",
11
+ "version": "1.4.17",
12
12
  "keywords": [],
13
13
  "author": "KHANHNBD <khanh272421@gmail.com>",
14
14
  "license": "ISC",