Skip to content

Commit 1b3aaab

Browse files
yihong0618jdneo
authored andcommitted
Change: dependency from prompt-sync to prompt for extention side to solve two-factor problem (#38)
1 parent 6a32f23 commit 1b3aaab

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

lib/plugins/leetcode.cn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict'
1+
'use strict';
22
var request = require('request');
33

44
var config = require('../config');

lib/plugins/leetcode.js

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var util = require('util');
33

44
var _ = require('underscore');
55
var request = require('request');
6+
var prompt = require('prompt');
67

78
var config = require('../config');
89
var h = require('../helper');
@@ -612,30 +613,39 @@ plugin.githubLogin = function(user, cb) {
612613
if (resp.request.uri.href !== urls.github_tf_redirect) {
613614
return requestLeetcodeAndSave(_request, leetcodeUrl, user, cb);
614615
}
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');
616+
prompt.colors = false;
617+
prompt.message = '';
618+
prompt.start();
619+
prompt.get([
620+
{
621+
name: 'twoFactorCode',
622+
required: true
623+
}
624+
], function(e, result) {
625+
if (e) return log.fail(e);
626+
const authenticityTokenTwoFactor = body.match(/name="authenticity_token" value="(.*?)"/);
627+
if (authenticityTokenTwoFactor === null) {
628+
return cb('Get GitHub two-factor token failed');
637629
}
638-
requestLeetcodeAndSave(_request, leetcodeUrl, user, cb);
630+
const optionsTwoFactor = {
631+
url: urls.github_tf_session_request,
632+
method: 'POST',
633+
headers: {
634+
'Content-Type': 'application/x-www-form-urlencoded',
635+
},
636+
followAllRedirects: true,
637+
form: {
638+
'otp': result.twoFactorCode,
639+
'authenticity_token': authenticityTokenTwoFactor[1],
640+
'utf8': encodeURIComponent('✓'),
641+
},
642+
};
643+
_request(optionsTwoFactor, function(e, resp, body) {
644+
if (resp.request.uri.href === urls.github_tf_session_request) {
645+
return cb('Invalid two-factor code please check');
646+
}
647+
requestLeetcodeAndSave(_request, leetcodeUrl, user, cb);
648+
});
639649
});
640650
});
641651
});

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"nock": "10.0.2",
7272
"nyc": "^13.3.0",
7373
"pkg": "^4.3.4",
74-
"prompt-sync": "^4.2.0",
7574
"rewire": "4.0.1"
7675
}
7776
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy