@@ -609,35 +609,34 @@ plugin.githubLogin = function(user, cb) {
609
609
if ( resp . statusCode !== 200 ) {
610
610
return cb ( 'GitHub login failed' ) ;
611
611
}
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 ( / n a m e = " a u t h e n t i c i t y _ t o k e n " v a l u e = " ( .* ?) " / ) ;
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 ( / n a m e = " a u t h e n t i c i t y _ t o k e n " v a l u e = " ( .* ?) " / ) ;
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' ) ;
618
637
}
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 {
639
638
requestLeetcodeAndSave ( _request , leetcodeUrl , user , cb ) ;
640
- }
639
+ } ) ;
641
640
} ) ;
642
641
} ) ;
643
642
} ;
0 commit comments