From 04b4dc11a81fc3dd58f69c155fe6eca66f4803d2 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Mon, 16 Dec 2019 13:35:45 +0800 Subject: [PATCH 1/5] add third party github login for future updates in vscode-leetcode and somehow solve the recaptcha problem --- README.md | 1 + lib/commands/user.js | 22 +++++++++++ lib/config.js | 2 + lib/plugins/leetcode.js | 83 ++++++++++++++++++++++++++++++++--------- 4 files changed, 91 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3b9f4680..c410fe9e 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Great thanks to leetcode.com, a really awesome website! Read help first $ leetcode help Login with your leetcode account $ leetcode user -l + Login with third party account--github $ leetcode user -g Cookie login with cookie $ leetcode user -c Browse all questions $ leetcode list Choose one question $ leetcode show 1 -g -l cpp diff --git a/lib/commands/user.js b/lib/commands/user.js index f5ae86b7..518ed207 100644 --- a/lib/commands/user.js +++ b/lib/commands/user.js @@ -27,6 +27,12 @@ const cmd = { default: false, describe: 'cookieLogin' }) + .option('g', { + alias: 'github', + type: 'boolean', + default: false, + describe: 'githubLogin' + }) .option('L', { alias: 'logout', type: 'boolean', @@ -36,6 +42,7 @@ const cmd = { .example(chalk.yellow('leetcode user'), 'Show current user') .example(chalk.yellow('leetcode user -l'), 'User login') .example(chalk.yellow('leetcode user -c'), 'User Cookie login') + .example(chalk.yellow('leetcode user -g'), 'User Github login') .example(chalk.yellow('leetcode user -L'), 'User logout'); } }; @@ -66,6 +73,21 @@ cmd.handler = function(argv) { log.info('Successfully logout as', chalk.yellow(user.name)); else log.fail('You are not login yet?'); + } else if (argv.github) { + // github + prompt.colors = false; + prompt.message = ''; + prompt.start(); + prompt.get([ + {name: 'login', required: true}, + {name: 'pass', required: true, hidden: true} + ], function(e, user) { + if (e) return log.fail(e) + core.githubLogin(user, function(e, user) { + if (e) return log.fail(e); + log.info('Successfully github login as', chalk.yellow(user.name)); + }); + }); } else if (argv.cookie) { // session prompt.colors = false; diff --git a/lib/config.js b/lib/config.js index 9708edfa..35673675 100644 --- a/lib/config.js +++ b/lib/config.js @@ -34,6 +34,8 @@ const DEFAULT_CONFIG = { base: 'https://leetcode.com', graphql: 'https://leetcode.com/graphql', login: 'https://leetcode.com/accounts/login/', + // third part login base urls. TODO facebook linkin google + github_login: 'https://leetcode.com/accounts/github/login/?next=%2F', problems: 'https://leetcode.com/api/problems/$category/', problem: 'https://leetcode.com/problems/$slug/description/', test: 'https://leetcode.com/problems/$slug/interpret_solution/', diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index 924b40d7..56b3c5dd 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -51,7 +51,7 @@ plugin.checkError = function(e, resp, expectedStatus) { plugin.init = function() { config.app = 'leetcode'; -} +}; plugin.getProblems = function(cb) { log.debug('running leetcode.getProblems'); @@ -95,7 +95,7 @@ plugin.getCategoryProblems = function(category, cb) { } const problems = json.stat_status_pairs - .filter(p => !p.stat.question__hide) + .filter((p) => !p.stat.question__hide) .map(function(p) { return { state: p.status || 'None', @@ -167,7 +167,7 @@ plugin.getProblem = function(problem, cb) { problem.testable = q.enableRunCode; problem.templateMeta = JSON.parse(q.metaData); // @si-yao: seems below property is never used. - //problem.discuss = q.discussCategoryId; + // problem.discuss = q.discussCategoryId; return cb(null, problem); }); @@ -254,9 +254,9 @@ function formatResult(result) { }; x.error = _.chain(result) - .pick((v, k) => /_error$/.test(k) && v.length > 0) - .values() - .value(); + .pick((v, k) => /_error$/.test(k) && v.length > 0) + .values() + .value(); if (/[runcode|interpret].*/.test(result.submission_id)) { // It's testing @@ -374,8 +374,8 @@ plugin.starProblem = function(problem, starred, cb) { }; } else { opts.url = config.sys.urls.favorite_delete - .replace('$hash', user.hash) - .replace('$id', problem.id); + .replace('$hash', user.hash) + .replace('$id', problem.id); opts.method = 'DELETE'; } @@ -508,7 +508,7 @@ plugin.signin = function(user, cb) { plugin.getUser = function(user, cb) { plugin.getFavorites(function(e, favorites) { if (!e) { - const f = favorites.favorites.private_favorites.find(f => f.name === 'Favorite'); + const f = favorites.favorites.private_favorites.find((f) => f.name === 'Favorite'); if (f) { user.hash = f.id_hash; user.name = favorites.user_name; @@ -538,19 +538,68 @@ plugin.login = function(user, cb) { }); }; -plugin.cookieLogin = function(user, cb) { - // re pattern for cookie chrome or firefox +function parseCookie(cookie, cb) { const SessionPattern = /LEETCODE_SESSION=(.+?)(;|$)/; const csrfPattern = /csrftoken=(.+?)(;|$)/; - const reSessionResult = SessionPattern.exec(user.cookie); - const reCsrfResult = csrfPattern.exec(user.cookie); + const reSessionResult = SessionPattern.exec(cookie); + const reCsrfResult = csrfPattern.exec(cookie); if (reSessionResult === null || reCsrfResult === null) { - return cb('invalid cookie?') + return cb('invalid cookie?'); } - user.sessionId = reSessionResult[1]; - user.sessionCSRF = reCsrfResult[1]; + return { + sessionId: reSessionResult[1], + sessionCSRF: reCsrfResult[1], + }; +} + +plugin.cookieLogin = function(user, cb) { + const cookieData = parseCookie(user.cookie, cb); + user.sessionId = cookieData.sessionId; + user.sessionCSRF = cookieData.sessionCSRF; session.saveUser(user); plugin.getUser(user, cb); -} +}; + +plugin.githubLogin = function(user, cb) { + const leetcodeUrl = config.sys.urls.github_login; + const _request = request.defaults({jar: true}); + _request('https://github.com/login', function(e, resp, body) { + const authenticityToken = body.match(/name="authenticity_token" value="(.*?)"/); + if (authenticityToken === null) { + return cb('Get github token failed'); + } + const options = { + url: 'https://github.com/session', + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + followAllRedirects: true, + form: { + 'login': user.login, + 'password': user.pass, + 'authenticity_token': authenticityToken[1], + 'utf8': encodeURIComponent('✓'), + 'commit': encodeURIComponent('Sign in') + }, + }; + _request(options, function(e, resp, body) { + if (resp.statusCode !== 200) { + return cb('Github login failed'); + } + _request.get({url: leetcodeUrl}, function(e, resp, body) { + const redirectUri = resp.request.uri.href; + if (redirectUri !== 'https://leetcode.com/') { + return cb('Github login failed or github did not link to leetcode'); + } + const cookieData = parseCookie(resp.request.headers.cookie, cb); + user.sessionId = cookieData.sessionId; + user.sessionCSRF = cookieData.sessionCSRF; + session.saveUser(user); + plugin.getUser(user, cb); + }); + }); + }); +}; module.exports = plugin; From 51ca691fe80a88dc55df594cfdd0f9d08f636feb Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Tue, 17 Dec 2019 22:23:52 +0800 Subject: [PATCH 2/5] add third party--Linkedin and fix typo by review. --- README.md | 17 +++---- lib/commands/user.js | 100 ++++++++++++++++++++++++---------------- lib/config.js | 8 ++-- lib/plugins/leetcode.js | 60 ++++++++++++++++++++++-- 4 files changed, 128 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index c410fe9e..23996f37 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,13 @@ Great thanks to leetcode.com, a really awesome website! ## Quick Start - Read help first $ leetcode help - Login with your leetcode account $ leetcode user -l - Login with third party account--github $ leetcode user -g - Cookie login with cookie $ leetcode user -c - Browse all questions $ leetcode list - Choose one question $ leetcode show 1 -g -l cpp + Read help first $ leetcode help + Login with your leetcode account $ leetcode user -l + Login with third party account--Github $ leetcode user -g + Login with third party account--Linkedin $ leetcode user -i + Cookie login with cookie $ leetcode user -c + Browse all questions $ leetcode list + Choose one question $ leetcode show 1 -g -l cpp Coding it! - Run test(s) and pray... $ leetcode test ./two-sum.cpp -t '[3,2,4]\n7' - Submit final solution! $ leetcode submit ./two-sum.cpp + Run test(s) and pray... $ leetcode test ./two-sum.cpp -t '[3,2,4]\n7' + Submit final solution! $ leetcode submit ./two-sum.cpp diff --git a/lib/commands/user.js b/lib/commands/user.js index 518ed207..f4d579f1 100644 --- a/lib/commands/user.js +++ b/lib/commands/user.js @@ -15,35 +15,42 @@ const cmd = { desc: 'Manage account', builder: function(yargs) { return yargs - .option('l', { - alias: 'login', - type: 'boolean', - default: false, - describe: 'Login' - }) - .option('c', { - alias: 'cookie', - type: 'boolean', - default: false, - describe: 'cookieLogin' - }) - .option('g', { - alias: 'github', - type: 'boolean', - default: false, - describe: 'githubLogin' - }) - .option('L', { - alias: 'logout', - type: 'boolean', - default: false, - describe: 'Logout' - }) - .example(chalk.yellow('leetcode user'), 'Show current user') - .example(chalk.yellow('leetcode user -l'), 'User login') - .example(chalk.yellow('leetcode user -c'), 'User Cookie login') - .example(chalk.yellow('leetcode user -g'), 'User Github login') - .example(chalk.yellow('leetcode user -L'), 'User logout'); + .option('l', { + alias: 'login', + type: 'boolean', + default: false, + describe: 'Login' + }) + .option('c', { + alias: 'cookie', + type: 'boolean', + default: false, + describe: 'cookieLogin' + }) + .option('g', { + alias: 'github', + type: 'boolean', + default: false, + describe: 'githubLogin' + }) + .option('i', { + alias: 'linkedin', + type: 'boolean', + default: false, + describe: 'linkinedLogin' + }) + .option('L', { + alias: 'logout', + type: 'boolean', + default: false, + describe: 'Logout' + }) + .example(chalk.yellow('leetcode user'), 'Show current user') + .example(chalk.yellow('leetcode user -l'), 'User login') + .example(chalk.yellow('leetcode user -c'), 'User Cookie login') + .example(chalk.yellow('leetcode user -g'), 'User Github login') + .example(chalk.yellow('leetcode user -i'), 'User Linkedin login') + .example(chalk.yellow('leetcode user -L'), 'User logout'); } }; @@ -73,8 +80,19 @@ cmd.handler = function(argv) { log.info('Successfully logout as', chalk.yellow(user.name)); else log.fail('You are not login yet?'); - } else if (argv.github) { - // github + // third parties + } else if (argv.github || argv.linkedin) { + // add future third parties here + const functionMap = new Map( + [ + ['g', core.githubLogin], + ['github', core.githubLogin], + ['i', core.linkinedLogin], + ['linkedin', core.linkedinLogin], + ] + ); + const keyword = Object.entries(argv).filter((i) => (i[1] === true))[0][0]; + const coreFunction = functionMap.get(keyword); prompt.colors = false; prompt.message = ''; prompt.start(); @@ -82,10 +100,10 @@ cmd.handler = function(argv) { {name: 'login', required: true}, {name: 'pass', required: true, hidden: true} ], function(e, user) { - if (e) return log.fail(e) - core.githubLogin(user, function(e, user) { if (e) return log.fail(e); - log.info('Successfully github login as', chalk.yellow(user.name)); + coreFunction(user, function(e, user) { + if (e) return log.fail(e); + log.info('Successfully third party login as', chalk.yellow(user.name)); }); }); } else if (argv.cookie) { @@ -97,22 +115,22 @@ cmd.handler = function(argv) { {name: 'login', required: true}, {name: 'cookie', required: true} ], function(e, user) { - if (e) return log.fail(e) - core.cookieLogin(user, function(e, user) { if (e) return log.fail(e); - log.info('Successfully cookie login as', chalk.yellow(user.name)); + core.cookieLogin(user, function(e, user) { + if (e) return log.fail(e); + log.info('Successfully cookie login as', chalk.yellow(user.name)); }); }); - } else { + } else { // show current user user = session.getUser(); if (user) { log.info(chalk.gray(sprintf(' %-9s %-20s %s', 'Premium', 'User', 'Host'))); log.info(chalk.gray('-'.repeat(60))); log.printf(' %s %-20s %s', - h.prettyText('', user.paid || false), - chalk.yellow(user.name), - config.sys.urls.base); + h.prettyText('', user.paid || false), + chalk.yellow(user.name), + config.sys.urls.base); } else return log.fail('You are not login yet?'); } diff --git a/lib/config.js b/lib/config.js index 35673675..7108f919 100644 --- a/lib/config.js +++ b/lib/config.js @@ -36,6 +36,8 @@ const DEFAULT_CONFIG = { login: 'https://leetcode.com/accounts/login/', // third part login base urls. TODO facebook linkin google github_login: 'https://leetcode.com/accounts/github/login/?next=%2F', + facebook_login: 'https://leetcode.com/accounts/facebook/login/?next=%2F', + linkined_login: 'https://leetcode.com/accounts/linkedin_oauth2/login/?next=%2F', problems: 'https://leetcode.com/api/problems/$category/', problem: 'https://leetcode.com/problems/$slug/description/', test: 'https://leetcode.com/problems/$slug/interpret_solution/', @@ -81,15 +83,15 @@ function Config() {} Config.prototype.init = function() { nconf.file('local', file.configFile()) - .add('global', {type: 'literal', store: DEFAULT_CONFIG}) - .defaults({}); + .add('global', {type: 'literal', store: DEFAULT_CONFIG}) + .defaults({}); const cfg = nconf.get(); nconf.remove('local'); nconf.remove('global'); // HACK: remove old style configs - for (let x in cfg) { + for (const x in cfg) { if (x === x.toUpperCase()) delete cfg[x]; } delete DEFAULT_CONFIG.type; diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index 56b3c5dd..f604a71f 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -552,6 +552,13 @@ function parseCookie(cookie, cb) { }; } +function saveAndGetUser(user, cb, cookieData) { + user.sessionId = cookieData.sessionId; + user.sessionCSRF = cookieData.sessionCSRF; + session.saveUser(user); + plugin.getUser(user, cb); +} + plugin.cookieLogin = function(user, cb) { const cookieData = parseCookie(user.cookie, cb); user.sessionId = cookieData.sessionId; @@ -590,13 +597,56 @@ plugin.githubLogin = function(user, cb) { _request.get({url: leetcodeUrl}, function(e, resp, body) { const redirectUri = resp.request.uri.href; if (redirectUri !== 'https://leetcode.com/') { - return cb('Github login failed or github did not link to leetcode'); + return cb('Github login failed or Github did not link to leetcode'); + } + const cookieData = parseCookie(resp.request.headers.cookie, cb); + saveAndGetUser(user, cb, cookieData); + }); + }); + }); +}; + +plugin.linkinedLogin = function(user, cb) { + const leetcodeUrl = config.sys.urls.linkined_login; + const _request = request.defaults({ + jar: true, + headers: { + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36' + } + }); + _request('https://www.linkedin.com', function(e, resp, body) { + if ( resp.statusCode !== 200) { + return cb('Get linkedin session failed'); + } + const authenticityToken = body.match(/input name="loginCsrfParam" value="(.*)" /); + if (authenticityToken === null) { + return cb('Get Linkined token failed'); + } + const options = { + url: 'https://www.linkedin.com/uas/login-submit', + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + followAllRedirects: true, + form: { + 'session_key': user.login, + 'session_password': user.pass, + 'loginCsrfParam': authenticityToken[1], + 'trk': 'guest_homepage-basic_sign-in-submit' + }, + }; + _request(options, function(e, resp, body) { + if (resp.statusCode !== 200) { + return cb('Facebook login failed'); + } + _request.get({url: leetcodeUrl}, function(e, resp, body) { + const redirectUri = resp.request.uri.href; + if (redirectUri !== 'https://leetcode.com/') { + return cb('Linkedin login failed or Linkedin did not link to leetcode'); } const cookieData = parseCookie(resp.request.headers.cookie, cb); - user.sessionId = cookieData.sessionId; - user.sessionCSRF = cookieData.sessionCSRF; - session.saveUser(user); - plugin.getUser(user, cb); + saveAndGetUser(user, cb, cookieData); }); }); }); From 57e39f8a0c787e608767edc2ec47407fbd057a63 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Wed, 18 Dec 2019 11:22:37 +0800 Subject: [PATCH 3/5] fix typo --- README.md | 2 +- lib/commands/user.js | 2 +- lib/plugins/leetcode.js | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 23996f37..0184c40d 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Great thanks to leetcode.com, a really awesome website! Read help first $ leetcode help Login with your leetcode account $ leetcode user -l - Login with third party account--Github $ leetcode user -g + Login with third party account--GitHub $ leetcode user -g Login with third party account--Linkedin $ leetcode user -i Cookie login with cookie $ leetcode user -c Browse all questions $ leetcode list diff --git a/lib/commands/user.js b/lib/commands/user.js index f4d579f1..ca9a10e3 100644 --- a/lib/commands/user.js +++ b/lib/commands/user.js @@ -48,7 +48,7 @@ const cmd = { .example(chalk.yellow('leetcode user'), 'Show current user') .example(chalk.yellow('leetcode user -l'), 'User login') .example(chalk.yellow('leetcode user -c'), 'User Cookie login') - .example(chalk.yellow('leetcode user -g'), 'User Github login') + .example(chalk.yellow('leetcode user -g'), 'User GitHub login') .example(chalk.yellow('leetcode user -i'), 'User Linkedin login') .example(chalk.yellow('leetcode user -L'), 'User logout'); } diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index f604a71f..6c923672 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -573,7 +573,7 @@ plugin.githubLogin = function(user, cb) { _request('https://github.com/login', function(e, resp, body) { const authenticityToken = body.match(/name="authenticity_token" value="(.*?)"/); if (authenticityToken === null) { - return cb('Get github token failed'); + return cb('Get GitHub token failed'); } const options = { url: 'https://github.com/session', @@ -592,12 +592,12 @@ plugin.githubLogin = function(user, cb) { }; _request(options, function(e, resp, body) { if (resp.statusCode !== 200) { - return cb('Github login failed'); + return cb('GitHub login failed'); } _request.get({url: leetcodeUrl}, function(e, resp, body) { const redirectUri = resp.request.uri.href; if (redirectUri !== 'https://leetcode.com/') { - return cb('Github login failed or Github did not link to leetcode'); + return cb('GitHub login failed or GitHub did not link to leetcode'); } const cookieData = parseCookie(resp.request.headers.cookie, cb); saveAndGetUser(user, cb, cookieData); @@ -620,7 +620,7 @@ plugin.linkinedLogin = function(user, cb) { } const authenticityToken = body.match(/input name="loginCsrfParam" value="(.*)" /); if (authenticityToken === null) { - return cb('Get Linkined token failed'); + return cb('Get Linkedin token failed'); } const options = { url: 'https://www.linkedin.com/uas/login-submit', @@ -638,7 +638,7 @@ plugin.linkinedLogin = function(user, cb) { }; _request(options, function(e, resp, body) { if (resp.statusCode !== 200) { - return cb('Facebook login failed'); + return cb('Linkedin login failed'); } _request.get({url: leetcodeUrl}, function(e, resp, body) { const redirectUri = resp.request.uri.href; From 3663a98d1a63d68de3725f36d55196ecf4933ec2 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Wed, 18 Dec 2019 19:01:57 +0800 Subject: [PATCH 4/5] fix typo --- README.md | 2 +- lib/commands/user.js | 6 +++--- lib/config.js | 4 ++-- lib/plugins/leetcode.js | 14 +++++++------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 0184c40d..686755c9 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Great thanks to leetcode.com, a really awesome website! Read help first $ leetcode help Login with your leetcode account $ leetcode user -l Login with third party account--GitHub $ leetcode user -g - Login with third party account--Linkedin $ leetcode user -i + Login with third party account--LinkedIn $ leetcode user -i Cookie login with cookie $ leetcode user -c Browse all questions $ leetcode list Choose one question $ leetcode show 1 -g -l cpp diff --git a/lib/commands/user.js b/lib/commands/user.js index ca9a10e3..a2534202 100644 --- a/lib/commands/user.js +++ b/lib/commands/user.js @@ -37,7 +37,7 @@ const cmd = { alias: 'linkedin', type: 'boolean', default: false, - describe: 'linkinedLogin' + describe: 'linkedinLogin' }) .option('L', { alias: 'logout', @@ -49,7 +49,7 @@ const cmd = { .example(chalk.yellow('leetcode user -l'), 'User login') .example(chalk.yellow('leetcode user -c'), 'User Cookie login') .example(chalk.yellow('leetcode user -g'), 'User GitHub login') - .example(chalk.yellow('leetcode user -i'), 'User Linkedin login') + .example(chalk.yellow('leetcode user -i'), 'User LinkedIn login') .example(chalk.yellow('leetcode user -L'), 'User logout'); } }; @@ -87,7 +87,7 @@ cmd.handler = function(argv) { [ ['g', core.githubLogin], ['github', core.githubLogin], - ['i', core.linkinedLogin], + ['i', core.linkedinLogin], ['linkedin', core.linkedinLogin], ] ); diff --git a/lib/config.js b/lib/config.js index 7108f919..049d20d4 100644 --- a/lib/config.js +++ b/lib/config.js @@ -34,10 +34,10 @@ const DEFAULT_CONFIG = { base: 'https://leetcode.com', graphql: 'https://leetcode.com/graphql', login: 'https://leetcode.com/accounts/login/', - // third part login base urls. TODO facebook linkin google + // third part login base urls. TODO facebook google github_login: 'https://leetcode.com/accounts/github/login/?next=%2F', facebook_login: 'https://leetcode.com/accounts/facebook/login/?next=%2F', - linkined_login: 'https://leetcode.com/accounts/linkedin_oauth2/login/?next=%2F', + linkedin_login: 'https://leetcode.com/accounts/linkedin_oauth2/login/?next=%2F', problems: 'https://leetcode.com/api/problems/$category/', problem: 'https://leetcode.com/problems/$slug/description/', test: 'https://leetcode.com/problems/$slug/interpret_solution/', diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index 6c923672..4f13a5ef 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -597,7 +597,7 @@ plugin.githubLogin = function(user, cb) { _request.get({url: leetcodeUrl}, function(e, resp, body) { const redirectUri = resp.request.uri.href; if (redirectUri !== 'https://leetcode.com/') { - return cb('GitHub login failed or GitHub did not link to leetcode'); + return cb('GitHub login failed or GitHub did not link to LeetCode'); } const cookieData = parseCookie(resp.request.headers.cookie, cb); saveAndGetUser(user, cb, cookieData); @@ -606,8 +606,8 @@ plugin.githubLogin = function(user, cb) { }); }; -plugin.linkinedLogin = function(user, cb) { - const leetcodeUrl = config.sys.urls.linkined_login; +plugin.linkedinLogin = function(user, cb) { + const leetcodeUrl = config.sys.urls.linkedin_login; const _request = request.defaults({ jar: true, headers: { @@ -616,11 +616,11 @@ plugin.linkinedLogin = function(user, cb) { }); _request('https://www.linkedin.com', function(e, resp, body) { if ( resp.statusCode !== 200) { - return cb('Get linkedin session failed'); + return cb('Get linkedIn session failed'); } const authenticityToken = body.match(/input name="loginCsrfParam" value="(.*)" /); if (authenticityToken === null) { - return cb('Get Linkedin token failed'); + return cb('Get LinkedIn token failed'); } const options = { url: 'https://www.linkedin.com/uas/login-submit', @@ -638,12 +638,12 @@ plugin.linkinedLogin = function(user, cb) { }; _request(options, function(e, resp, body) { if (resp.statusCode !== 200) { - return cb('Linkedin login failed'); + return cb('LinkedIn login failed'); } _request.get({url: leetcodeUrl}, function(e, resp, body) { const redirectUri = resp.request.uri.href; if (redirectUri !== 'https://leetcode.com/') { - return cb('Linkedin login failed or Linkedin did not link to leetcode'); + return cb('LinkedIn login failed or LinkedIn did not link to LeetCode'); } const cookieData = parseCookie(resp.request.headers.cookie, cb); saveAndGetUser(user, cb, cookieData); From a3c2dc6c3ee73f396a3699d1e841499fba8a8b2b Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Wed, 18 Dec 2019 19:16:27 +0800 Subject: [PATCH 5/5] fix another typo --- lib/plugins/leetcode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index 4f13a5ef..004a6034 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -616,7 +616,7 @@ plugin.linkedinLogin = function(user, cb) { }); _request('https://www.linkedin.com', function(e, resp, body) { if ( resp.statusCode !== 200) { - return cb('Get linkedIn session failed'); + return cb('Get LinkedIn session failed'); } const authenticityToken = body.match(/input name="loginCsrfParam" value="(.*)" /); if (authenticityToken === null) {