@@ -555,8 +555,8 @@ function parseCookie(cookie, cb) {
555
555
function requestLeetcodeAndSave ( request , leetcodeUrl , user , cb , party ) {
556
556
request . get ( { url : leetcodeUrl } , function ( e , resp , body ) {
557
557
const redirectUri = resp . request . uri . href ;
558
- if ( redirectUri !== 'https://leetcode.com/' ) {
559
- return cb ( `${ party } login failed or ${ party } did not link to LeetCode` ) ;
558
+ if ( redirectUri !== config . sys . urls . leetcode_redirect ) {
559
+ return cb ( `${ party } login failed or ${ party } did not connect to LeetCode` ) ;
560
560
}
561
561
const cookieData = parseCookie ( resp . request . headers . cookie , cb ) ;
562
562
user . sessionId = cookieData . sessionId ;
@@ -575,15 +575,16 @@ plugin.cookieLogin = function(user, cb) {
575
575
} ;
576
576
577
577
plugin . githubLogin = function ( user , cb ) {
578
- const leetcodeUrl = config . sys . urls . github_login ;
578
+ const urls = config . sys . urls
579
+ const leetcodeUrl = urls . github_login ;
579
580
const _request = request . defaults ( { jar : true } ) ;
580
- _request ( 'https://github.com/login' , function ( e , resp , body ) {
581
+ _request ( urls . github_login_request , function ( e , resp , body ) {
581
582
const authenticityToken = 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 = " ( .* ?) " / ) ;
582
583
if ( authenticityToken === null ) {
583
584
return cb ( 'Get GitHub token failed' ) ;
584
585
}
585
586
const options = {
586
- url : 'https://github.com/session' ,
587
+ url : urls . github_session_request ,
587
588
method : 'POST' ,
588
589
headers : {
589
590
'Content-Type' : 'application/x-www-form-urlencoded' ,
@@ -601,16 +602,16 @@ plugin.githubLogin = function(user, cb) {
601
602
if ( resp . statusCode !== 200 ) {
602
603
return cb ( 'GitHub login failed' ) ;
603
604
}
604
- if ( resp . request . uri . href == 'https://github.com/sessions/two-factor' ) {
605
- cb ( 'Your Github are using two-factor authentication' ) ;
605
+ if ( resp . request . uri . href === urls . github_tf_redirect ) {
606
+ cb ( 'Your GitHub are using two-factor authentication' ) ;
606
607
// read two-factor code must be sync.
607
608
const twoFactorcode = require ( 'prompt-sync' ) ( ) ( 'Please enter your two-factor code: ' ) ;
608
609
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 = " ( .* ?) " / ) ;
609
610
if ( authenticityTokenTwoFactor === null ) {
610
611
return cb ( 'Get GitHub two-factor token failed' ) ;
611
612
}
612
613
const optionsTwoFactor = {
613
- url : 'https://github.com/sessions/two-factor' ,
614
+ url : urls . github_tf_session_request ,
614
615
method : 'POST' ,
615
616
headers : {
616
617
'Content-Type' : 'application/x-www-form-urlencoded' ,
@@ -623,27 +624,28 @@ plugin.githubLogin = function(user, cb) {
623
624
} ,
624
625
} ;
625
626
_request ( optionsTwoFactor , function ( e , resp , body ) {
626
- if ( resp . request . uri . href === 'https://github.com/sessions/two-factor' ) {
627
- return cb ( 'Wrong two-factor code please check' ) ;
627
+ if ( resp . request . uri . href === urls . github_tf_session_request ) {
628
+ return cb ( 'Invalid two-factor code please check' ) ;
628
629
}
629
- requestLeetcodeAndSave ( _request , leetcodeUrl , user , cb , ' GitHub' ) ;
630
+ requestLeetcodeAndSave ( _request , leetcodeUrl , user , cb , config . sys . login_methods . GitHub ) ;
630
631
} ) ;
631
632
} else {
632
- requestLeetcodeAndSave ( _request , leetcodeUrl , user , cb , ' GitHub' ) ;
633
+ requestLeetcodeAndSave ( _request , leetcodeUrl , user , cb , config . sys . login_methods . GitHub ) ;
633
634
}
634
635
} ) ;
635
636
} ) ;
636
637
} ;
637
638
638
639
plugin . linkedinLogin = function ( user , cb ) {
639
- const leetcodeUrl = config . sys . urls . linkedin_login ;
640
+ const urls = config . sys . urls
641
+ const leetcodeUrl = urls . linkedin_login ;
640
642
const _request = request . defaults ( {
641
643
jar : true ,
642
644
headers : {
643
645
'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'
644
646
}
645
647
} ) ;
646
- _request ( 'https://www.linkedin.com' , function ( e , resp , body ) {
648
+ _request ( urls . linkedin_login_request , function ( e , resp , body ) {
647
649
if ( resp . statusCode !== 200 ) {
648
650
return cb ( 'Get LinkedIn session failed' ) ;
649
651
}
@@ -652,7 +654,7 @@ plugin.linkedinLogin = function(user, cb) {
652
654
return cb ( 'Get LinkedIn token failed' ) ;
653
655
}
654
656
const options = {
655
- url : 'https://www.linkedin.com/uas/login-submit' ,
657
+ url : urls . linkedin_session_request ,
656
658
method : 'POST' ,
657
659
headers : {
658
660
'Content-Type' : 'application/x-www-form-urlencoded' ,
@@ -669,7 +671,7 @@ plugin.linkedinLogin = function(user, cb) {
669
671
if ( resp . statusCode !== 200 ) {
670
672
return cb ( 'LinkedIn login failed' ) ;
671
673
}
672
- requestLeetcodeAndSave ( _request , leetcodeUrl , user , cb , ' LinkedIn' ) ;
674
+ requestLeetcodeAndSave ( _request , leetcodeUrl , user , cb , config . sys . login_methods . LinkedIn ) ;
673
675
} ) ;
674
676
} ) ;
675
677
} ;
0 commit comments