MCPcopy Index your code
hub / github.com/LeetCode-OpenSource/vscode-leetcode / signIn

Method signIn

src/leetCodeManager.ts:39–146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37 }
38
39 public async signIn(): Promise<void> {
40 const picks: Array<IQuickItemEx<string>> = [];
41 picks.push(
42 {
43 label: "LeetCode Account",
44 detail: "Use LeetCode account to login (US endpoint is not supported)",
45 value: "LeetCode",
46 },
47 {
48 label: "Third-Party: GitHub",
49 detail: "Use GitHub account to login",
50 value: "GitHub",
51 },
52 {
53 label: "Third-Party: LinkedIn",
54 detail: "Use LinkedIn account to login",
55 value: "LinkedIn",
56 },
57 {
58 label: "LeetCode Cookie",
59 detail: "Use LeetCode cookie copied from browser to login",
60 value: "Cookie",
61 },
62 );
63 const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(picks);
64 if (!choice) {
65 return;
66 }
67 const loginMethod: string = choice.value;
68 const commandArg: string | undefined = loginArgsMapping.get(loginMethod);
69 if (!commandArg) {
70 throw new Error(`The login method "${loginMethod}" is not supported.`);
71 }
72 const isByCookie: boolean = loginMethod === "Cookie";
73 const inMessage: string = isByCookie ? "sign in by cookie" : "sign in";
74 try {
75 const userName: string | undefined = await new Promise(async (resolve: (res: string | undefined) => void, reject: (e: Error) => void): Promise<void> => {
76
77 const leetCodeBinaryPath: string = await leetCodeExecutor.getLeetCodeBinaryPath();
78
79 const childProc: cp.ChildProcess = wsl.useWsl()
80 ? cp.spawn("wsl", [leetCodeExecutor.node, leetCodeBinaryPath, "user", commandArg], { shell: true })
81 : cp.spawn(leetCodeExecutor.node, [leetCodeBinaryPath, "user", commandArg], {
82 shell: true,
83 env: createEnvOption(),
84 });
85
86 childProc.stdout?.on("data", async (data: string | Buffer) => {
87 data = data.toString();
88 leetCodeChannel.append(data);
89 if (data.includes("twoFactorCode")) {
90 const twoFactor: string | undefined = await vscode.window.showInputBox({
91 prompt: "Enter two-factor code.",
92 ignoreFocusOut: true,
93 validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "The input must not be empty",
94 });
95 if (!twoFactor) {
96 childProc.kill();

Callers 1

activateFunction · 0.80

Calls 4

createEnvOptionFunction · 0.90
getLeetCodeBinaryPathMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected