@@ -14,6 +14,8 @@ import * as wsl from "./utils/wslUtils";
|
14 | 14 | class LeetCodeManager extends EventEmitter {
|
15 | 15 | private currentUser: string | undefined;
|
16 | 16 | private userStatus: UserStatus;
|
| 17 | +private readonly successRegex: RegExp = /(?:.*)Successfully .*login as (.*)/i; |
| 18 | +private readonly failRegex: RegExp = /.*\[ERROR\].*/i; |
17 | 19 |
|
18 | 20 | constructor() {
|
19 | 21 | super();
|
@@ -42,11 +44,6 @@ class LeetCodeManager extends EventEmitter {
|
42 | 44 | detail: "Use LeetCode account to login",
|
43 | 45 | value: "LeetCode",
|
44 | 46 | },
|
45 |
| -{ |
46 |
| -label: "LeetCode Cookie", |
47 |
| -detail: "Use LeetCode cookie copied from browser to login", |
48 |
| -value: "Cookie", |
49 |
| -}, |
50 | 47 | {
|
51 | 48 | label: "Third-Party: ",
|
52 | 49 | detail: "Use account to login",
|
@@ -57,6 +54,11 @@ class LeetCodeManager extends EventEmitter {
|
57 | 54 | detail: "Use LinkedIn account to login",
|
58 | 55 | value: "LinkedIn",
|
59 | 56 | },
|
| 57 | +{ |
| 58 | +label: "LeetCode Cookie", |
| 59 | +detail: "Use LeetCode cookie copied from browser to login", |
| 60 | +value: "Cookie", |
| 61 | +}, |
60 | 62 | );
|
61 | 63 | const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(picks);
|
62 | 64 | if (!choice) {
|
@@ -87,20 +89,22 @@ class LeetCodeManager extends EventEmitter {
|
87 | 89 | if (data.includes("twoFactorCode")) {
|
88 | 90 | const twoFactor: string | undefined = await vscode.window.showInputBox({
|
89 | 91 | prompt: "Enter two-factor code.",
|
| 92 | +ignoreFocusOut: true, |
90 | 93 | validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "The input must not be empty",
|
91 | 94 | });
|
92 | 95 | if (!twoFactor) {
|
93 | 96 | childProc.kill();
|
94 | 97 | return resolve(undefined);
|
95 | 98 | }
|
96 | 99 | childProc.stdin.write(`${twoFactor}\n`);
|
| 100 | +} |
| 101 | +const successMatch: RegExpMatchArray | null = data.match(this.successRegex); |
| 102 | +if (successMatch && successMatch[1]) { |
97 | 103 | childProc.stdin.end();
|
98 |
| -} else { |
99 |
| -const match: RegExpMatchArray | null = data.match(/(?:.*)Successfully .*login as (.*)/i); |
100 |
| -if (match && match[1]) { |
101 |
| -childProc.stdin.end(); |
102 |
| -return resolve(match[1]); |
103 |
| -} |
| 104 | +return resolve(successMatch[1]); |
| 105 | +} else if (data.match(this.failRegex)) { |
| 106 | +childProc.stdin.end(); |
| 107 | +return reject(new Error("Faile to login")); |
104 | 108 | }
|
105 | 109 | });
|
106 | 110 |
|
@@ -109,6 +113,7 @@ class LeetCodeManager extends EventEmitter {
|
109 | 113 | childProc.on("error", reject);
|
110 | 114 | const name: string | undefined = await vscode.window.showInputBox({
|
111 | 115 | prompt: "Enter username or E-mail.",
|
| 116 | +ignoreFocusOut: true, |
112 | 117 | validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "The input must not be empty",
|
113 | 118 | });
|
114 | 119 | if (!name) {
|
@@ -119,18 +124,14 @@ class LeetCodeManager extends EventEmitter {
|
119 | 124 | const pwd: string | undefined = await vscode.window.showInputBox({
|
120 | 125 | prompt: isByCookie ? "Enter cookie" : "Enter password.",
|
121 | 126 | password: true,
|
| 127 | +ignoreFocusOut: true, |
122 | 128 | validateInput: (s: string): string | undefined => s ? undefined : isByCookie ? "Cookie must not be empty" : "Password must not be empty",
|
123 | 129 | });
|
124 | 130 | if (!pwd) {
|
125 | 131 | childProc.kill();
|
126 | 132 | return resolve(undefined);
|
127 | 133 | }
|
128 | 134 | childProc.stdin.write(`${pwd}\n`);
|
129 |
| -childProc.on("close", (code: number) => { |
130 |
| -if (code !== 0) { |
131 |
| -reject(new Error("Failed to login.")); |
132 |
| -} |
133 |
| -}); |
134 | 135 | });
|
135 | 136 | if (userName) {
|
136 | 137 | vscode.window.showInformationMessage(`Successfully ${inMessage}.`);
|
|
0 commit comments