mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
vjudge: codeforces: fix login check
This commit is contained in:
4 files changed
+17
-13
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/vjudge",
|
"name": "@hydrooj/vjudge",
|
||||||
"version": "1.8.5",
|
"version": "1.8.6",
|
||||||
"description": "Submit problems to remote oj",
|
"description": "Submit problems to remote oj",
|
||||||
"main": "src/model.ts",
|
"main": "src/model.ts",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -33,10 +33,11 @@ export class BasicFetcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async html(url: string) {
|
async html(url: string) {
|
||||||
const { text: html } = await this.get(url);
|
const { text: html, headers } = await this.get(url);
|
||||||
const $dom = new JSDOM(html);
|
const $dom = new JSDOM(html);
|
||||||
$dom.window.html = html;
|
$dom.window.html = html;
|
||||||
return $dom.window as DOMWindow & { html: string };
|
$dom.window.headers = headers;
|
||||||
|
return $dom.window as DOMWindow & { html: string, headers: any };
|
||||||
}
|
}
|
||||||
|
|
||||||
post(url: string) {
|
post(url: string) {
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ class AccountService {
|
|||||||
await coll.updateOne({ _id: account._id }, { $set: data });
|
await coll.updateOne({ _id: account._id }, { $set: data });
|
||||||
});
|
});
|
||||||
this.problemLists = Set.union(this.api.entryProblemLists || ['main'], this.account.problemLists || []);
|
this.problemLists = Set.union(this.api.entryProblemLists || ['main'], this.account.problemLists || []);
|
||||||
this.main().catch((e) => logger.error(`Error occured in ${account.type}/${account.handle}`, e));
|
this.main().catch((e) => {
|
||||||
|
logger.error(`Error occured in ${account.type}/${account.handle}`);
|
||||||
|
console.error(e);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async addProblemList(name: string) {
|
async addProblemList(name: string) {
|
||||||
|
|||||||
@@ -83,37 +83,37 @@ export default class CodeforcesProvider extends BasicFetcher implements IBasicPr
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getCsrfToken(url: string) {
|
async getCsrfToken(url: string) {
|
||||||
const { document, html } = await this.html(url);
|
const { document, html, headers } = await this.html(url);
|
||||||
if (document.body.children.length < 2 && html.length < 512) {
|
if (document.body.children.length < 2 && html.length < 512) {
|
||||||
throw new Error(document.body.textContent);
|
throw new Error(document.body.textContent!);
|
||||||
}
|
}
|
||||||
const ftaa = this.getCookie('70a7c28f3de');
|
const ftaa = this.getCookie('70a7c28f3de') || 'n/a';
|
||||||
const bfaa = /_bfaa = "(.{32})"/.exec(html)?.[1] || this.getCookie('raa') || this.getCookie('bfaa');
|
const bfaa = this.getCookie('raa') || this.getCookie('bfaa') || 'n/a';
|
||||||
return [
|
return [
|
||||||
(
|
(
|
||||||
document.querySelector('meta[name="X-Csrf-Token"]')
|
document.querySelector('meta[name="X-Csrf-Token"]')
|
||||||
|| document.querySelector('input[name="csrf_token"]')
|
|| document.querySelector('input[name="csrf_token"]')
|
||||||
)?.getAttribute('content'),
|
)?.getAttribute('content'),
|
||||||
ftaa, bfaa,
|
ftaa, bfaa, headers,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
get loggedIn() {
|
get loggedIn() {
|
||||||
return this.get('/enter').then((res) => {
|
return this.get('/').then((res) => {
|
||||||
const html = res.text;
|
const html = res.text;
|
||||||
if (html.includes('Login into Codeforces')) return false;
|
|
||||||
if (html.length < 1000 && html.includes('Redirecting...')) {
|
if (html.length < 1000 && html.includes('Redirecting...')) {
|
||||||
logger.debug('Got a redirect', html);
|
logger.debug('Got a redirect', html);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return html.includes('header-bell__img');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async ensureLogin() {
|
async ensureLogin() {
|
||||||
if (await this.loggedIn) return true;
|
if (await this.loggedIn) return true;
|
||||||
logger.info('retry normal login');
|
logger.info('retry normal login');
|
||||||
const [csrf, ftaa, bfaa] = await this.getCsrfToken('/enter');
|
const [csrf, ftaa, bfaa, header] = await this.getCsrfToken('/enter');
|
||||||
|
if (header['set-cookie']) this.setCookie(header['set-cookie']);
|
||||||
const res = await this.post('/enter').send({
|
const res = await this.post('/enter').send({
|
||||||
csrf_token: csrf,
|
csrf_token: csrf,
|
||||||
action: 'enter',
|
action: 'enter',
|
||||||
|
|||||||
Reference in new issue
Block a user