@@ -34,16 +34,20 @@ class LeetCodeManager extends EventEmitter {
34
34
}
35
35
}
36
36
37
- public async signIn ( ) : Promise < void > {
37
+ public async signIn ( isByCookie : boolean = false ) : Promise < void > {
38
+ const loginArg : string = "-l" ;
39
+ const cookieArg : string = "-c" ;
40
+ const commandArg : string = isByCookie ? cookieArg : loginArg ;
41
+ const inMessage : string = isByCookie ? "sign in by cookie" : "sign in" ;
38
42
try {
39
43
const userName : string | undefined = await new Promise ( async ( resolve : ( res : string | undefined ) => void , reject : ( e : Error ) => void ) : Promise < void > => {
40
44
let result : string = "" ;
41
45
42
46
const leetCodeBinaryPath : string = await leetCodeExecutor . getLeetCodeBinaryPath ( ) ;
43
47
44
48
const childProc : cp . ChildProcess = wsl . useWsl ( )
45
- ? cp . spawn ( "wsl" , [ leetCodeExecutor . node , leetCodeBinaryPath , "user" , "-l" ] , { shell : true } )
46
- : cp . spawn ( leetCodeExecutor . node , [ leetCodeBinaryPath , "user" , "-l" ] , {
49
+ ? cp . spawn ( "wsl" , [ leetCodeExecutor . node , leetCodeBinaryPath , "user" , commandArg ] , { shell : true } )
50
+ : cp . spawn ( leetCodeExecutor . node , [ leetCodeBinaryPath , "user" , commandArg ] , {
47
51
shell : true ,
48
52
env : createEnvOption ( ) ,
49
53
} ) ;
@@ -67,9 +71,9 @@ class LeetCodeManager extends EventEmitter {
67
71
}
68
72
childProc . stdin . write ( `${ name } \n` ) ;
69
73
const pwd : string | undefined = await vscode . window . showInputBox ( {
70
- prompt : "Enter password." ,
74
+ prompt : isByCookie ? "Enter cookie" : "Enter password." ,
71
75
password : true ,
72
- validateInput : ( s : string ) : string | undefined => s ? undefined : "Password must not be empty" ,
76
+ validateInput : ( s : string ) : string | undefined => s ? undefined : isByCookie ? "Cookie must not be empty" : "Password must not be empty" ,
73
77
} ) ;
74
78
if ( ! pwd ) {
75
79
childProc . kill ( ) ;
@@ -78,22 +82,22 @@ class LeetCodeManager extends EventEmitter {
78
82
childProc . stdin . write ( `${ pwd } \n` ) ;
79
83
childProc . stdin . end ( ) ;
80
84
childProc . on ( "close" , ( ) => {
81
- const match : RegExpMatchArray | null = result . match ( / (?: .* ) S u c c e s s f u l l y l o g i n a s ( .* ) / i) ;
82
- if ( match && match [ 1 ] ) {
83
- resolve ( match [ 1 ] ) ;
85
+ const match : RegExpMatchArray | null = result . match ( / (?: .* ) S u c c e s s f u l l y ( l o g i n | c o o k i e l o g i n ) a s ( .* ) / i) ;
86
+ if ( match && match [ 2 ] ) {
87
+ resolve ( match [ 2 ] ) ;
84
88
} else {
85
- reject ( new Error ( " Failed to sign in." ) ) ;
89
+ reject ( new Error ( ` Failed to ${ inMessage } .` ) ) ;
86
90
}
87
91
} ) ;
88
92
} ) ;
89
93
if ( userName ) {
90
- vscode . window . showInformationMessage ( " Successfully signed in." ) ;
94
+ vscode . window . showInformationMessage ( ` Successfully ${ inMessage } .` ) ;
91
95
this . currentUser = userName ;
92
96
this . userStatus = UserStatus . SignedIn ;
93
97
this . emit ( "statusChanged" ) ;
94
98
}
95
99
} catch ( error ) {
96
- promptForOpenOutputChannel ( " Failed to sign in . Please open the output channel for details" , DialogType . error ) ;
100
+ promptForOpenOutputChannel ( ` Failed to ${ inMessage } . Please open the output channel for details` , DialogType . error ) ;
97
101
}
98
102
99
103
}
0 commit comments