Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

add thrid party login -- GitHub and LinkedIn#496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jdneo merged 13 commits intoLeetCode-OpenSource:masterfromyihong0618:master
Jan 12, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
af76a8b
add leetcode.cookieIn but simple change
yihong0618Dec 3, 2019
3124790
try to fix ci first time
yihong0618Dec 3, 2019
6ab8a3b
try to fix ci second time
yihong0618Dec 3, 2019
8d24d57
rename cookie in to Sign in (by cookie)
yihong0618Dec 4, 2019
ae2fa04
also change readme-cn
yihong0618Dec 4, 2019
ed51cb5
fix preposition typo
yihong0618Dec 5, 2019
e9fbd35
Merge remote-tracking branch 'upstream/master'
yihong0618Dec 20, 2019
e4606fc
add thrid party login -- GitHub and LinkedIn
yihong0618Dec 20, 2019
ae9463e
fix lint bug
yihong0618Dec 20, 2019
4b0577e
make login methods in one pop up
yihong0618Dec 27, 2019
f52cde3
delete comments and change cli version for ci
yihong0618Dec 27, 2019
a7f2ff0
make naming more formal by review
yihong0618Dec 29, 2019
b05f9d4
add two-factor support for GitHub login
yihong0618Jan 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,11 +51,9 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh

- Simply click `Sign in to LeetCode` in the `LeetCode Explorer` will let you **sign in** with your LeetCode account.

- You can also use the following command to sign in/sign in (by cookie)/out:
- You can also use the following command to sign in/out:
- **LeetCode: Sign in**
- **LeetCode: Sign in (by cookie)**
- **LeetCode: Sign out**

---

### Switch Endpoint
Expand Down
2 changes: 0 additions & 2 deletionsdocs/README_zh-CN.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,9 +53,7 @@

- 你也可以使用下来命令登入或利用cookie登入或登出:
- **LeetCode: Sign in**
- **LeetCode: Sign in (by cookie)**
- **LeetCode: Sign out**

---

### 切换 LeetCode 版本
Expand Down
8 changes: 1 addition & 7 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,17 +38,11 @@
"onCommand:leetcode.testSolution",
"onCommand:leetcode.submitSolution",
"onCommand:leetcode.switchDefaultLanguage",
"onCommand:leetcode.signinByCookie",
"onView:leetCodeExplorer"
],
"main": "./out/src/extension",
"contributes": {
"commands": [
{
"command": "leetcode.signinByCookie",
"title": "Sign In by Cookie",
"category": "LeetCode"
},
{
"command": "leetcode.deleteCache",
"title": "Delete Cache",
Expand DownExpand Up@@ -689,6 +683,6 @@
"markdown-it": "^8.4.2",
"require-from-string": "^2.0.2",
"unescape-js": "^1.1.1",
"vsc-leetcode-cli": "2.6.19"
"vsc-leetcode-cli": "2.6.20"
}
}
1 change: 0 additions & 1 deletionsrc/extension.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,7 +51,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
vscode.commands.registerCommand("leetcode.deleteCache", () => cache.deleteCache()),
vscode.commands.registerCommand("leetcode.toggleLeetCodeCn", () => plugin.switchEndpoint()),
vscode.commands.registerCommand("leetcode.signin", () => leetCodeManager.signIn()),
vscode.commands.registerCommand("leetcode.signinByCookie", () => leetCodeManager.signIn(true)),
vscode.commands.registerCommand("leetcode.signout", () => leetCodeManager.signOut()),
vscode.commands.registerCommand("leetcode.manageSessions", () => session.manageSessions()),
vscode.commands.registerCommand("leetcode.previewProblem", (node: LeetCodeNode) => show.previewProblem(node)),
Expand Down
72 changes: 57 additions & 15 deletionssrc/leetCodeManager.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ import { EventEmitter } from "events";
import * as vscode from "vscode";
import { leetCodeChannel } from "./leetCodeChannel";
import { leetCodeExecutor } from "./leetCodeExecutor";
import { UserStatus } from "./shared";
import {IQuickItemEx, loginArgsMapping,UserStatus } from "./shared";
import { createEnvOption } from "./utils/cpUtils";
import { DialogType, promptForOpenOutputChannel } from "./utils/uiUtils";
import * as wsl from "./utils/wslUtils";
Expand DownExpand Up@@ -34,14 +34,43 @@ class LeetCodeManager extends EventEmitter {
}
}

public async signIn(isByCookie: boolean = false): Promise<void> {
const loginArg: string = "-l";
const cookieArg: string = "-c";
const commandArg: string = isByCookie ? cookieArg : loginArg;
public async signIn(): Promise<void> {
const picks: Array<IQuickItemEx<string>> = [];
picks.push(
{
label: "LeetCode Account",
detail: "Use LeetCode account to login",
value: "LeetCode",
},
{
label: "LeetCode Cookie",
detail: "Use LeetCode cookie copied from browser to login",
value: "Cookie",
},
{
label: "Third-Party: GitHub",
detail: "Use GitHub account to login",
value: "GitHub",
},
{
label: "Third-Party: LinkedIn",
detail: "Use LinkedIn account to login",
value: "LinkedIn",
},
);
const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(picks);
if (!choice) {
return;
}
const loginMethod: string = choice.value;
const commandArg: string | undefined = loginArgsMapping.get(loginMethod);
if (!commandArg) {
throw new Error(`The login method "${loginMethod}" is not supported.`);
}
const isByCookie: boolean = loginMethod === "Cookie";
const inMessage: string = isByCookie ? "sign in by cookie" : "sign in";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is this variableinMessage used anywhere?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, it is for the difference of cookie login or other login message.
e.g.

promptForOpenOutputChannel(Failed to ${inMessage}. Please open the output channel for details

try {
const userName: string | undefined = await new Promise(async (resolve: (res: string | undefined) => void, reject: (e: Error) => void): Promise<void> => {
let result: string = "";

const leetCodeBinaryPath: string = await leetCodeExecutor.getLeetCodeBinaryPath();

Expand All@@ -52,10 +81,27 @@ class LeetCodeManager extends EventEmitter {
env: createEnvOption(),
});

childProc.stdout.on("data", (data: string | Buffer) => {
childProc.stdout.on("data",async(data: string | Buffer) => {
data = data.toString();
result = result.concat(data);
leetCodeChannel.append(data);
if (data.includes("twoFactorCode")) {
const twoFactor: string | undefined = await vscode.window.showInputBox({
prompt: "Enter two-factor code.",
validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "The input must not be empty",
});
if (!twoFactor) {
childProc.kill();
return resolve(undefined);
}
childProc.stdin.write(`${twoFactor}\n`);
childProc.stdin.end();
} else {
const match: RegExpMatchArray | null = data.match(/(?:.*)Successfully .*login as (.*)/i);
if (match && match[1]) {
childProc.stdin.end();
return resolve(match[1]);
}
}
});

childProc.stderr.on("data", (data: string | Buffer) => leetCodeChannel.append(data.toString()));
Expand All@@ -80,13 +126,9 @@ class LeetCodeManager extends EventEmitter {
return resolve(undefined);
}
childProc.stdin.write(`${pwd}\n`);
childProc.stdin.end();
childProc.on("close", () => {
const match: RegExpMatchArray | null = result.match(/(?:.*) Successfully (login|cookie login) as (.*)/i);
if (match && match[2]) {
resolve(match[2]);
} else {
reject(new Error(`Failed to ${inMessage}.`));
childProc.on("close", (code: number) => {
if (code !== 0) {
reject(new Error("Failed to login."));
}
});
});
Expand Down
7 changes: 7 additions & 0 deletionssrc/shared.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,13 @@ export enum UserStatus {
SignedOut = 2,
}

export const loginArgsMapping: Map<string, string> = new Map([
["LeetCode", "-l"],
["Cookie", "-c"],
["GitHub", "-g"],
["LinkedIn", "-i"],
]);

export const languages: string[] = [
"bash",
"c",
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp