-
Notifications
You must be signed in to change notification settings - Fork 26
/
server.js
30 lines (28 loc) · 1.08 KB
/
server.js
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
const request = require('request');
module.exports = function (options) {
const { loginUrl, emailPostfix } = options;
this.bindHook('third_login', (ctx) => {
let token = ctx.request.body.token || ctx.request.query.token;
return new Promise((resolve, reject) => {
request(loginUrl + token, function (error, response, body) {
if (!error && response.statusCode == 200) {
let result = JSON.parse(body);
if (result && result.ret === true) {
let ret = {
email: result.userId + emailPostfix,
username: result.data.userInfo.name
};
const next = ctx.request.body.next;
if (next) {
ret.next = next;
}
resolve(ret);
} else {
reject(result);
}
}
reject(error);
});
});
});
};