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

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
merged 13 commits into from
Jan 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
add leetcode.cookieIn but simple change
  • Loading branch information
yihong0618 committed Dec 3, 2019
commit af76a8b3927c79ebfa1bcd5b486416637ca755e3
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@

- 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/out:
- You can also use the following command to sign in/cookie in/out:
- **LeetCode: Sign in**
- **LeetCode: Cookie in**
- **LeetCode: Sign out**

---
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@
"onCommand:leetcode.testSolution",
"onCommand:leetcode.submitSolution",
"onCommand:leetcode.switchDefaultLanguage",
"onCommand:leetcode.cookieIn",
"onView:leetCodeExplorer"
],
"main": "./out/src/extension",
"contributes": {
"commands": [
{
"command": "leetcode.cookieIn",
"title": "Cookie In",
"category": "LeetCode"
},
{
"command": "leetcode.deleteCache",
"title": "Delete Cache",
Expand Down Expand Up @@ -683,6 +689,6 @@
"markdown-it": "^8.4.2",
"require-from-string": "^2.0.2",
"unescape-js": "^1.1.1",
"vsc-leetcode-cli": "2.6.16"
"vsc-leetcode-cli": "2.6.17"
}
}
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ 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.cookieIn", () => 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
26 changes: 15 additions & 11 deletions src/leetCodeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ class LeetCodeManager extends EventEmitter {
}
}

public async signIn(): Promise<void> {
public async signIn(isCookieIn = false): Promise<void> {
const loginArg = "-l";
const cookieInArg = "-c";
const commandArg = isCookieIn ? cookieInArg : loginArg;
const inMessage = isCookieIn ? "cookie in" : "sign in"
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();

const childProc: cp.ChildProcess = wsl.useWsl()
? cp.spawn("wsl", [leetCodeExecutor.node, leetCodeBinaryPath, "user", "-l"], { shell: true })
: cp.spawn(leetCodeExecutor.node, [leetCodeBinaryPath, "user", "-l"], {
? cp.spawn("wsl", [leetCodeExecutor.node, leetCodeBinaryPath, "user", commandArg], { shell: true })
: cp.spawn(leetCodeExecutor.node, [leetCodeBinaryPath, "user", commandArg], {
shell: true,
env: createEnvOption(),
});
Expand All @@ -67,9 +71,9 @@ class LeetCodeManager extends EventEmitter {
}
childProc.stdin.write(`${name}\n`);
const pwd: string | undefined = await vscode.window.showInputBox({
prompt: "Enter password.",
prompt: isCookieIn ? "Enter cookie" : "Enter password.",
password: true,
validateInput: (s: string): string | undefined => s ? undefined : "Password must not be empty",
validateInput: (s: string): string | undefined => s ? undefined : isCookieIn ? "Cookie must not be empty" : "Password must not be empty",
});
if (!pwd) {
childProc.kill();
Expand All @@ -78,22 +82,22 @@ class LeetCodeManager extends EventEmitter {
childProc.stdin.write(`${pwd}\n`);
childProc.stdin.end();
childProc.on("close", () => {
const match: RegExpMatchArray | null = result.match(/(?:.*) Successfully login as (.*)/i);
if (match && match[1]) {
resolve(match[1]);
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 sign in."));
reject(new Error(`Failed to ${inMessage}.`));
}
});
});
if (userName) {
vscode.window.showInformationMessage("Successfully signed in.");
vscode.window.showInformationMessage(`Successfully ${inMessage}.`);
this.currentUser = userName;
this.userStatus = UserStatus.SignedIn;
this.emit("statusChanged");
}
} catch (error) {
promptForOpenOutputChannel("Failed to sign in. Please open the output channel for details", DialogType.error);
promptForOpenOutputChannel(`Failed to ${inMessage}. Please open the output channel for details`, DialogType.error);
}

}
Expand Down