From 8b22e3abf9648ce251f00bc8cbd9e14d2d9ee229 Mon Sep 17 00:00:00 2001 From: yihong Date: Thu, 18 Jun 2020 21:21:12 +0800 Subject: [PATCH] fix: leetcode-cn can not use GitHub log in bug --- lib/plugins/leetcode.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index 8855f689..7790bb97 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -540,10 +540,16 @@ plugin.login = function(user, cb) { }; function parseCookie(cookie, body, cb) { + const isCN = config.app === 'leetcode.cn'; const SessionPattern = /LEETCODE_SESSION=(.+?)(;|$)/; - const csrfPattern = /csrftoken=(.+?)(;|$)/; + let csrfPattern; + if (isCN) { + csrfPattern = /name="csrfmiddlewaretoken" value="(.*?)"/; + } else { + csrfPattern = /csrftoken=(.+?)(;|$)/; + } + const reCsrfResult = csrfPattern.exec(isCN? body: cookie); const reSessionResult = SessionPattern.exec(cookie); - const reCsrfResult = csrfPattern.exec(cookie); if (reSessionResult === null || reCsrfResult === null) { return cb('invalid cookie?'); }