Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1c45e40

Browse files
fix: leetcode-cn can not use GitHub log in bug (leetcode-tools#46)
1 parent 404420e commit 1c45e40

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

‎lib/plugins/leetcode.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,16 @@ plugin.login = function(user, cb) {
540540
};
541541

542542
function parseCookie(cookie, body, cb) {
543+
const isCN = config.app === 'leetcode.cn';
543544
const SessionPattern = /LEETCODE_SESSION=(.+?)(;|$)/;
544-
const csrfPattern = /csrftoken=(.+?)(;|$)/;
545+
let csrfPattern;
546+
if (isCN) {
547+
csrfPattern = /name="csrfmiddlewaretoken"value="(.*?)"/;
548+
} else {
549+
csrfPattern = /csrftoken=(.+?)(;|$)/;
550+
}
551+
const reCsrfResult = csrfPattern.exec(isCN? body: cookie);
545552
const reSessionResult = SessionPattern.exec(cookie);
546-
const reCsrfResult = csrfPattern.exec(cookie);
547553
if (reSessionResult === null || reCsrfResult === null) {
548554
return cb('invalid cookie?');
549555
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /