mdkcontroller 1.4.15 → 1.4.16

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
 
@@ -78,6 +109,9 @@ export default function () {
78
109
  validateBool: (req, res) => {
79
110
  return validateBase(req, res);
80
111
  },
112
+ validateByToken: (accessToken) => {
113
+ return validateBaseByToken(accessToken);
114
+ },
81
115
  encrypt: function (data = "", pw = "mdkpaswoEcrHidDefat") {
82
116
  return encrypt(data, pw);
83
117
  },
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.16",
12
12
  "keywords": [],
13
13
  "author": "KHANHNBD <khanh272421@gmail.com>",
14
14
  "license": "ISC",