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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
jdneo merged 13 commits into LeetCode-OpenSource:master from yihong0618:master
Jan 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit Hold shift + click to select a range
af76a8b
add leetcode.cookieIn but simple change
yihong0618 Dec 3, 2019
3124790
try to fix ci first time
yihong0618 Dec 3, 2019
6ab8a3b
try to fix ci second time
yihong0618 Dec 3, 2019
8d24d57
rename cookie in to Sign in (by cookie)
yihong0618 Dec 4, 2019
ae2fa04
also change readme-cn
yihong0618 Dec 4, 2019
ed51cb5
fix preposition typo
yihong0618 Dec 5, 2019
e9fbd35
Merge remote-tracking branch 'upstream/master'
yihong0618 Dec 20, 2019
e4606fc
add thrid party login -- GitHub and LinkedIn
yihong0618 Dec 20, 2019
ae9463e
fix lint bug
yihong0618 Dec 20, 2019
4b0577e
make login methods in one pop up
yihong0618 Dec 27, 2019
f52cde3
delete comments and change cli version for ci
yihong0618 Dec 27, 2019
a7f2ff0
make naming more formal by review
yihong0618 Dec 29, 2019
b05f9d4
add two-factor support for GitHub login
yihong0618 Jan 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
Prev Previous commit
Next Next commit
add thrid party login -- GitHub and LinkedIn
  • Loading branch information
yihong0618 committed Dec 20, 2019
commit e4606fc430fda239a6ce0223c541e4983c6f9dc0
3 changes: 3 additions & 0 deletions README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
- **LeetCode: Sign in (by cookie)**
- **LeetCode: Sign out**

- You can also use the following command to sign in by third party:
Copy link
Member

Choose a reason for hiding this comment

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

Please only reserve the common login command as it was before.

- **LeetCode: Sign in by GitHub**
- **LeetCode: Sign in by LinkedIn**
---

### Switch Endpoint
Expand Down
3 changes: 3 additions & 0 deletions docs/README_zh-CN.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
- **LeetCode: Sign in (by cookie)**
- **LeetCode: Sign out**

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

### 切换 LeetCode 版本
Expand Down
22 changes: 17 additions & 5 deletions package.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,13 @@
"onCommand:leetcode.submitSolution",
"onCommand:leetcode.switchDefaultLanguage",
"onCommand:leetcode.signinByCookie",
"onCommand:leetcode.signinByGitHub",
"onCommand:leetcode.signinByLinkedIn",
"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 All @@ -72,6 +69,21 @@
"dark": "resources/dark/signin.svg"
}
},
{
"command": "leetcode.signinByCookie",
"title": "Sign In by Cookie",
"category": "LeetCode"
},
{
"command": "leetcode.signinByGitHub",
"title": "Sign In by GitHub",
"category": "LeetCode"
},
{
"command": "leetcode.signinByLinkedIn",
"title": "Sign In by LinkedIn",
"category": "LeetCode"
},
{
"command": "leetcode.signout",
"title": "Sign Out",
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
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.signinByGitHub", () => leetCodeManager.signIn(false, "GitHub")),
vscode.commands.registerCommand("leetcode.signinByLinkedIn", () => leetCodeManager.signIn(false, "LinkedIn")),
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
11 changes: 7 additions & 4 deletions src/leetCodeManager.ts
View file Open in desktop
Original file line number Diff line number Diff 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 { UserStatus, LoginCommand } from "./shared";
import { createEnvOption } from "./utils/cpUtils";
import { DialogType, promptForOpenOutputChannel } from "./utils/uiUtils";
import * as wsl from "./utils/wslUtils";
Expand Down Expand Up @@ -34,8 +34,11 @@ class LeetCodeManager extends EventEmitter {
}
}

public async signIn(isByCookie: boolean = false): Promise<void> {
const loginArg: string = "-l";
public async signIn(isByCookie: boolean = false, thirdParty: string = "Default"): Promise<void> {
const loginArg: string | undefined = LoginCommand.get(thirdParty);
if (!loginArg) {
throw new Error(`The third party "${thirdParty}" is not supported.`);
}
const cookieArg: string = "-c";
const commandArg: string = isByCookie ? cookieArg : loginArg;
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 variable inMessage used anywhere?

Copy link
Contributor Author

@yihong0618 yihong0618 Dec 29, 2019

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

Expand Down Expand Up @@ -82,7 +85,7 @@ class LeetCodeManager extends EventEmitter {
childProc.stdin.write(`${pwd}\n`);
childProc.stdin.end();
childProc.on("close", () => {
const match: RegExpMatchArray | null = result.match(/(?:.*) Successfully (login|cookie login) as (.*)/i);
const match: RegExpMatchArray | null = result.match(/(?:.*) Successfully (login|cookie login|third party login) as (.*)/i);
if (match && match[2]) {
resolve(match[2]);
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/shared.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export enum UserStatus {
SignedOut = 2,
}

export const LoginCommand: Map<string, string> = new Map([
["Default", "-l"],
["GitHub", "-g"],
["LinkedIn", "-i"],
]);

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

AltStyle によって変換されたページ (->オリジナル) /