Skip to content

Commit

Permalink
fix: can't sign in by cookie on leetcode-cn site
Browse files Browse the repository at this point in the history
  • Loading branch information
dzz007 committed Mar 21, 2021
1 parent cd5d4ef commit bca58ab
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/plugins/leetcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?');
Expand Down

0 comments on commit bca58ab

Please sign in to comment.