Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1cdf7f8

Browse files
committed
delete unused config and make the github login function more clear by review
1 parent e3680fe commit 1cdf7f8

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

lib/config.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ const DEFAULT_CONFIG = {
6161
favorite_delete: 'https://leetcode.com/list/api/questions/$hash/$id',
6262
plugin: 'https://raw.githubusercontent.com/leetcode-tools/leetcode-cli-plugins/master/plugins/$name.js'
6363
},
64-
// login methods enum
65-
login_methods: {
66-
LeetCode: 'LeetCode',
67-
Cookie: 'Cookie',
68-
GitHub: 'Github',
69-
LinkedIn: 'LinkedIn'
70-
}
7164
},
7265

7366
// but you will want change these

lib/plugins/leetcode.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -609,35 +609,34 @@ plugin.githubLogin = function(user, cb) {
609609
if (resp.statusCode !== 200) {
610610
return cb('GitHub login failed');
611611
}
612-
if (resp.request.uri.href === urls.github_tf_redirect) {
613-
// read two-factor code must be sync.
614-
const twoFactorcode = require('prompt-sync')()('Please enter your two-factor code: ');
615-
const authenticityTokenTwoFactor = body.match(/name="authenticity_token" value="(.*?)"/);
616-
if (authenticityTokenTwoFactor === null) {
617-
return cb('Get GitHub two-factor token failed');
612+
if (resp.request.uri.href !== urls.github_tf_redirect) {
613+
return requestLeetcodeAndSave(_request, leetcodeUrl, user, cb);
614+
}
615+
// read two-factor code must be sync.
616+
const twoFactorcode = require('prompt-sync')()('Please enter your two-factor code: ');
617+
const authenticityTokenTwoFactor = body.match(/name="authenticity_token" value="(.*?)"/);
618+
if (authenticityTokenTwoFactor === null) {
619+
return cb('Get GitHub two-factor token failed');
620+
}
621+
const optionsTwoFactor = {
622+
url: urls.github_tf_session_request,
623+
method: 'POST',
624+
headers: {
625+
'Content-Type': 'application/x-www-form-urlencoded',
626+
},
627+
followAllRedirects: true,
628+
form: {
629+
'otp': twoFactorcode,
630+
'authenticity_token': authenticityTokenTwoFactor[1],
631+
'utf8': encodeURIComponent('✓'),
632+
},
633+
};
634+
_request(optionsTwoFactor, function(e, resp, body) {
635+
if (resp.request.uri.href === urls.github_tf_session_request) {
636+
return cb('Invalid two-factor code please check');
618637
}
619-
const optionsTwoFactor = {
620-
url: urls.github_tf_session_request,
621-
method: 'POST',
622-
headers: {
623-
'Content-Type': 'application/x-www-form-urlencoded',
624-
},
625-
followAllRedirects: true,
626-
form: {
627-
'otp': twoFactorcode,
628-
'authenticity_token': authenticityTokenTwoFactor[1],
629-
'utf8': encodeURIComponent('✓'),
630-
},
631-
};
632-
_request(optionsTwoFactor, function(e, resp, body) {
633-
if (resp.request.uri.href === urls.github_tf_session_request) {
634-
return cb('Invalid two-factor code please check');
635-
}
636-
requestLeetcodeAndSave(_request, leetcodeUrl, user, cb);
637-
});
638-
} else {
639638
requestLeetcodeAndSave(_request, leetcodeUrl, user, cb);
640-
}
639+
});
641640
});
642641
});
643642
};

0 commit comments

Comments
 (0)