login.js
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const Service = require('egg').Service;
class LoginService extends Service {
async localLogin(user,access_token='') {
const { ctx, config={}, app, logger } = this;
const { restful={} } = config;
const { host, port, tokenUrl,tokenMethod} = restful;
const result = await ctx.curl(`${host}:${port}${tokenUrl}`, {
method: `${tokenMethod}`,
dataType: 'json',
data: JSON.stringify(ctx.request.body),
headers: {
'authorization': `Bearer ${access_token}`,
'accept': 'application/json',
'content-type': 'application/json'
},
timeout: [5000, 60000]
});
ctx.session.user_info = result.data;
return result;
}
async changeTant(params) {
const { ctx, config={}, logger } = this;
const {session} = ctx
const { restful={} } = config;
const { access_token } = session.user_info;
const { host, port, tokenUrl,tokenMethod} = restful;
const result = await ctx.curl(`${host}:${port}${tokenUrl}`, {
method: `${tokenMethod}`,
dataType: 'json',
data: JSON.stringify(params),
headers: {
'authorization': `Bearer ${access_token}`,
'accept': 'application/json',
'content-type': 'application/json'
},
timeout: [5000, 60000]
});
ctx.session.user_info = result.data;
return result;
}
}
module.exports = LoginService;