From bca58ab3e8e228ce0ecacfa18226312c611372f9 Mon Sep 17 00:00:00 2001 From: Zhizhang Deng Date: Sun, 21 Mar 2021 11:18:16 -0400 Subject: [PATCH 1/2] fix: can't sign in by cookie on leetcode-cn site --- lib/plugins/leetcode.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index c403582d..87ebccf5 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -534,15 +534,10 @@ plugin.login = function(user, cb) { }; function parseCookie(cookie, body, cb) { - const isCN = config.app === 'leetcode.cn'; const SessionPattern = /LEETCODE_SESSION=(.+?)(;|$)/; let csrfPattern; - if (isCN) { - csrfPattern = /name="csrfmiddlewaretoken" value="(.*?)"/; - } else { - csrfPattern = /csrftoken=(.+?)(;|$)/; - } - const reCsrfResult = csrfPattern.exec(isCN? body: cookie); + csrfPattern = /csrftoken=(.+?)(;|$)/; + const reCsrfResult = csrfPattern.exec(cookie); const reSessionResult = SessionPattern.exec(cookie); if (reSessionResult === null || reCsrfResult === null) { return cb('invalid cookie?'); From 59db3a165b164bdd4a158490ce973e92d854cb8d Mon Sep 17 00:00:00 2001 From: Zhizhang Deng Date: Mon, 29 Mar 2021 04:55:45 -0400 Subject: [PATCH 2/2] Used const instead of let --- lib/plugins/leetcode.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index 87ebccf5..c66d7cfc 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -535,8 +535,7 @@ plugin.login = function(user, cb) { function parseCookie(cookie, body, cb) { const SessionPattern = /LEETCODE_SESSION=(.+?)(;|$)/; - let csrfPattern; - csrfPattern = /csrftoken=(.+?)(;|$)/; + const csrfPattern = /csrftoken=(.+?)(;|$)/; const reCsrfResult = csrfPattern.exec(cookie); const reSessionResult = SessionPattern.exec(cookie); if (reSessionResult === null || reCsrfResult === null) {