Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e4606fc

Browse files
committed
add thrid party login -- GitHub and LinkedIn
1 parent e9fbd35 commit e4606fc

File tree

6 files changed

+38
-9
lines changed

6 files changed

+38
-9
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
5656
- **LeetCode: Sign in (by cookie)**
5757
- **LeetCode: Sign out**
5858

59+
- You can also use the following command to sign in by third party:
60+
- **LeetCode: Sign in by GitHub**
61+
- **LeetCode: Sign in by LinkedIn**
5962
---
6063

6164
### Switch Endpoint

docs/README_zh-CN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
- **LeetCode: Sign in (by cookie)**
5757
- **LeetCode: Sign out**
5858

59+
- 你也可以使用下列命令第三方登入:
60+
- **LeetCode: Sign in by GitHub**
61+
- **LeetCode: Sign in by LinkedIn**
5962
---
6063

6164
### 切换 LeetCode 版本

package.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,13 @@
3939
"onCommand:leetcode.submitSolution",
4040
"onCommand:leetcode.switchDefaultLanguage",
4141
"onCommand:leetcode.signinByCookie",
42+
"onCommand:leetcode.signinByGitHub",
43+
"onCommand:leetcode.signinByLinkedIn",
4244
"onView:leetCodeExplorer"
4345
],
4446
"main": "./out/src/extension",
4547
"contributes": {
4648
"commands": [
47-
{
48-
"command": "leetcode.signinByCookie",
49-
"title": "Sign In by Cookie",
50-
"category": "LeetCode"
51-
},
5249
{
5350
"command": "leetcode.deleteCache",
5451
"title": "Delete Cache",
@@ -72,6 +69,21 @@
7269
"dark": "resources/dark/signin.svg"
7370
}
7471
},
72+
{
73+
"command": "leetcode.signinByCookie",
74+
"title": "Sign In by Cookie",
75+
"category": "LeetCode"
76+
},
77+
{
78+
"command": "leetcode.signinByGitHub",
79+
"title": "Sign In by GitHub",
80+
"category": "LeetCode"
81+
},
82+
{
83+
"command": "leetcode.signinByLinkedIn",
84+
"title": "Sign In by LinkedIn",
85+
"category": "LeetCode"
86+
},
7587
{
7688
"command": "leetcode.signout",
7789
"title": "Sign Out",

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
5252
vscode.commands.registerCommand("leetcode.toggleLeetCodeCn", () => plugin.switchEndpoint()),
5353
vscode.commands.registerCommand("leetcode.signin", () => leetCodeManager.signIn()),
5454
vscode.commands.registerCommand("leetcode.signinByCookie", () => leetCodeManager.signIn(true)),
55+
vscode.commands.registerCommand("leetcode.signinByGitHub", () => leetCodeManager.signIn(false, "GitHub")),
56+
vscode.commands.registerCommand("leetcode.signinByLinkedIn", () => leetCodeManager.signIn(false, "LinkedIn")),
5557
vscode.commands.registerCommand("leetcode.signout", () => leetCodeManager.signOut()),
5658
vscode.commands.registerCommand("leetcode.manageSessions", () => session.manageSessions()),
5759
vscode.commands.registerCommand("leetcode.previewProblem", (node: LeetCodeNode) => show.previewProblem(node)),

src/leetCodeManager.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { EventEmitter } from "events";
66
import * as vscode from "vscode";
77
import { leetCodeChannel } from "./leetCodeChannel";
88
import { leetCodeExecutor } from "./leetCodeExecutor";
9-
import { UserStatus } from "./shared";
9+
import { UserStatus, LoginCommand } from "./shared";
1010
import { createEnvOption } from "./utils/cpUtils";
1111
import { DialogType, promptForOpenOutputChannel } from "./utils/uiUtils";
1212
import * as wsl from "./utils/wslUtils";
@@ -34,8 +34,11 @@ class LeetCodeManager extends EventEmitter {
3434
}
3535
}
3636

37-
public async signIn(isByCookie: boolean = false): Promise<void> {
38-
const loginArg: string = "-l";
37+
public async signIn(isByCookie: boolean = false, thirdParty: string = "Default"): Promise<void> {
38+
const loginArg: string | undefined = LoginCommand.get(thirdParty);
39+
if (!loginArg) {
40+
throw new Error(`The third party "${thirdParty}" is not supported.`);
41+
}
3942
const cookieArg: string = "-c";
4043
const commandArg: string = isByCookie ? cookieArg : loginArg;
4144
const inMessage: string = isByCookie ? "sign in by cookie" : "sign in";
@@ -82,7 +85,7 @@ class LeetCodeManager extends EventEmitter {
8285
childProc.stdin.write(`${pwd}\n`);
8386
childProc.stdin.end();
8487
childProc.on("close", () => {
85-
const match: RegExpMatchArray | null = result.match(/(?:.*) Successfully (login|cookie login) as (.*)/i);
88+
const match: RegExpMatchArray | null = result.match(/(?:.*) Successfully (login|cookie login|third party login) as (.*)/i);
8689
if (match && match[2]) {
8790
resolve(match[2]);
8891
} else {

src/shared.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export enum UserStatus {
1212
SignedOut = 2,
1313
}
1414

15+
export const LoginCommand: Map<string, string> = new Map([
16+
["Default", "-l"],
17+
["GitHub", "-g"],
18+
["LinkedIn", "-i"],
19+
]);
20+
1521
export const languages: string[] = [
1622
"bash",
1723
"c",

0 commit comments

Comments
 (0)