-
Notifications
You must be signed in to change notification settings - Fork 5
/
user.js
45 lines (41 loc) · 1.12 KB
/
user.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var users = {}, ghUsers = {}, fbUsers = {},
request = require("request");
exports.get = function(login) {
if(login.type == 'github') {
}
}
function authFb(callback) {
request("https://graph.facebook.com/me?fields=id&access_token=" + data.token,
function(err,res,body) {
if(err) {
result.resolve(defer.reject("Can't reach facebook"));
return;
}
if(body.error || body.id!=data.fbid) {
result.resolve(defer.reject("Wrong facebook account " + data.remoteId));
return;
}
result.resolve(fetchUser(account.userId));
}
);
return result.promise;
}
function authGh() {
var url = "https://api.github.com/user?access_token=" + data.token;
request({uri:url, headers: {"User-Agent":"askabt.com"}},
function(err,res,body) {
log("Github token auth took " + (new Date() - start) + "ms");
body = parse.parseUrlEncoded(body);
if(err) {
result.resolve(defer.reject("Can't reach github"));
return;
}
if(body.message) {
result.resolve(defer.reject("Wrong github account " + body.message));
return;
}
result.resolve(fetchUser(account.userId));
}
);
return result.promise;
}