-
Notifications
You must be signed in to change notification settings - Fork 665
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
Changes from 11 commits
af76a8b
3124790
6ab8a3b
8d24d57
ae2fa04
ed51cb5
e9fbd35
e4606fc
ae9463e
4b0577e
f52cde3
a7f2ff0
b05f9d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, loginCommand, UserStatus } from "./shared"; | ||
import { createEnvOption } from "./utils/cpUtils"; | ||
import { DialogType, promptForOpenOutputChannel } from "./utils/uiUtils"; | ||
import * as wsl from "./utils/wslUtils"; | ||
|
@@ -34,10 +34,44 @@ 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", | ||
description: "", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to set the field |
||
detail: "Use LeetCode account to login", | ||
value: "LeetCode", | ||
}, | ||
{ | ||
label: "LeetCode Cookie", | ||
description: "", | ||
detail: "Use LeetCode cookie that copy from browser to login", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use LeetCode cookie copied from browser to login |
||
value: "Cookie", | ||
}, | ||
{ | ||
label: "Third-Party: GitHub", | ||
description: "", | ||
detail: "Use third party GitHub account to login", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use GitHub account to login |
||
value: "GitHub", | ||
}, | ||
{ | ||
label: "Third-Party: LinkedIn", | ||
description: "", | ||
detail: "Use third party LinkedIn account to login", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 = loginCommand.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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this variable There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
|
||
try { | ||
const userName: string | undefined = await new Promise(async (resolve: (res: string | undefined) => void, reject: (e: Error) => void): Promise<void> => { | ||
|
@@ -82,7 +116,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 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,13 @@ export enum UserStatus { | |
SignedOut = 2, | ||
} | ||
|
||
export const loginCommand: Map<string, string> = new Map([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. loginCommand -> loginArgsMapping |
||
["LeetCode", "-l"], | ||
["Cookie", "-c"], | ||
["GitHub", "-g"], | ||
["LinkedIn", "-i"], | ||
]); | ||
|
||
export const languages: string[] = [ | ||
"bash", | ||
"c", | ||
|
There was a problem hiding this comment.
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.