@modular-rest/server 1.11.12 → 1.11.13
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 +1 -1
- package/src/services/jwt/router.js +43 -31
- package/types/middlewares.d.ts +1 -0
package/package.json
CHANGED
|
@@ -7,64 +7,76 @@ let verify = new Router();
|
|
|
7
7
|
|
|
8
8
|
let service = require('./service').main;
|
|
9
9
|
|
|
10
|
-
verify.post('/token', async (ctx) =>
|
|
11
|
-
{
|
|
10
|
+
verify.post('/token', async (ctx) => {
|
|
12
11
|
let body = ctx.request.body;
|
|
13
12
|
|
|
14
13
|
// validate result
|
|
15
14
|
let bodyValidate = validateObject(body, 'token');
|
|
16
15
|
|
|
17
16
|
// fields validation
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
if (!bodyValidate.isValid) {
|
|
18
|
+
ctx.status = 412;
|
|
19
|
+
ctx.body = reply('e', {
|
|
20
|
+
'e': bodyValidate.requires
|
|
21
|
+
});
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
24
|
|
|
25
25
|
await service.verify(body.token)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
.then((payload) => ctx.body = reply('s', {
|
|
27
|
+
'user': payload
|
|
28
|
+
}))
|
|
29
|
+
.catch(err => {
|
|
30
|
+
ctx.status = 412;
|
|
31
|
+
ctx.body = reply('e', {
|
|
32
|
+
'e': err
|
|
33
|
+
});
|
|
34
|
+
});
|
|
31
35
|
});
|
|
32
36
|
|
|
33
|
-
verify.post('/checkAccess', async (ctx) =>
|
|
34
|
-
{
|
|
37
|
+
verify.post('/checkAccess', async (ctx) => {
|
|
35
38
|
let body = ctx.request.body;
|
|
36
39
|
|
|
37
40
|
// validate result
|
|
38
41
|
let bodyValidate = validateObject(body, 'token permissionField');
|
|
39
42
|
|
|
40
43
|
// fields validation
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
if (!bodyValidate.isValid) {
|
|
45
|
+
ctx.status = 412;
|
|
46
|
+
ctx.body = reply('e', {
|
|
47
|
+
'e': bodyValidate.requires
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
46
50
|
}
|
|
47
|
-
|
|
51
|
+
|
|
48
52
|
let payload = await service.verify(body.token)
|
|
49
53
|
.catch(err => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
console.log(err);
|
|
55
|
+
ctx.throw(412, err.message);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
|
|
55
59
|
let userid = payload.id;
|
|
56
|
-
|
|
60
|
+
|
|
57
61
|
await global.services.userManager.main.getUserById(userid)
|
|
58
|
-
.then((user) =>
|
|
59
|
-
{
|
|
62
|
+
.then((user) => {
|
|
60
63
|
let key = user.hasPermission(body.permissionField);
|
|
61
|
-
ctx.body = reply('s', {
|
|
64
|
+
ctx.body = reply('s', {
|
|
65
|
+
'access': key
|
|
66
|
+
});
|
|
62
67
|
})
|
|
63
68
|
.catch(err => {
|
|
64
69
|
ctx.status = 412;
|
|
65
|
-
ctx.body = reply('e', {
|
|
70
|
+
ctx.body = reply('e', {
|
|
71
|
+
'e': err
|
|
72
|
+
});
|
|
66
73
|
});
|
|
67
74
|
});
|
|
68
75
|
|
|
76
|
+
verify.get('/ready', async (ctx) => {
|
|
77
|
+
// it's health check, so return success
|
|
78
|
+
ctx.body = reply('s', {});
|
|
79
|
+
});
|
|
80
|
+
|
|
69
81
|
module.exports.name = name;
|
|
70
82
|
module.exports.main = verify;
|
package/types/middlewares.d.ts
CHANGED