Skip to content

Commit

Permalink
fix: leetcode-cn can not use GitHub log in bug (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
yihong0618 authored Jun 27, 2020
1 parent 404420e commit 1c45e40
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/plugins/leetcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?');
}
Expand Down

0 comments on commit 1c45e40

Please sign in to comment.