Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1b3aaab

Browse files
yihong0618jdneo
authored andcommitted
Change: dependency from prompt-sync to prompt for extention side to solve two-factor problem (#38)
1 parent6a32f23 commit1b3aaab

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
varrequest=require('request');
33

44
varconfig=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
varrequest=require('request');
6+
varprompt=require('prompt');
67

78
varconfig=require('../config');
89
varh=require('../helper');
@@ -612,30 +613,39 @@ plugin.githubLogin = function(user, cb) {
612613
if(resp.request.uri.href!==urls.github_tf_redirect){
613614
returnrequestLeetcodeAndSave(_request,leetcodeUrl,user,cb);
614615
}
615-
// read two-factor code must be sync.
616-
consttwoFactorcode=require('prompt-sync')()('Please enter your two-factor code: ');
617-
constauthenticityTokenTwoFactor=body.match(/name="authenticity_token"value="(.*?)"/);
618-
if(authenticityTokenTwoFactor===null){
619-
returncb('Get GitHub two-factor token failed');
620-
}
621-
constoptionsTwoFactor={
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-
returncb('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)returnlog.fail(e);
626+
constauthenticityTokenTwoFactor=body.match(/name="authenticity_token"value="(.*?)"/);
627+
if(authenticityTokenTwoFactor===null){
628+
returncb('Get GitHub two-factor token failed');
637629
}
638-
requestLeetcodeAndSave(_request,leetcodeUrl,user,cb);
630+
constoptionsTwoFactor={
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+
returncb('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)

[8]ページ先頭

©2009-2025 Movatter.jp