mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
vjudge: luogu: fix login
This commit is contained in:
1 parent
1f585968a4
commit
bc43b2fd4e
3 files changed
+21
-3
No files matched your search
@@ -47,4 +47,9 @@ export class BasicFetcher {
|
||||
if (this.fetchOptions.post?.headers) req = req.set(this.fetchOptions.post.headers);
|
||||
return this.account.proxy ? req.proxy(this.account.proxy) : req;
|
||||
}
|
||||
|
||||
setCookie(cookie: string | string[]) {
|
||||
if (typeof cookie === 'string') this.cookie = [cookie];
|
||||
else this.cookie = cookie;
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ export default class CodeforcesProvider extends BasicFetcher implements IBasicPr
|
||||
const cookie = res.header['set-cookie'];
|
||||
if (cookie) {
|
||||
await this.save({ cookie });
|
||||
this.cookie = cookie;
|
||||
this.setCookie(cookie);
|
||||
}
|
||||
if (await this.loggedIn) {
|
||||
logger.success('Logged in');
|
||||
|
||||
@@ -41,7 +41,10 @@ export default class LuoguProvider extends BasicFetcher implements IBasicProvide
|
||||
},
|
||||
},
|
||||
});
|
||||
setInterval(() => this.getCsrfToken('/user/setting'), 5 * 60 * 1000);
|
||||
setInterval(() => {
|
||||
this.ensureLogin();
|
||||
this.getCsrfToken('/user/setting');
|
||||
}, 5 * 60 * 1000);
|
||||
}
|
||||
|
||||
async getCsrfToken(url: string) {
|
||||
@@ -60,7 +63,17 @@ export default class LuoguProvider extends BasicFetcher implements IBasicProvide
|
||||
return true;
|
||||
}
|
||||
logger.info('retry login');
|
||||
// TODO login;
|
||||
const res = await this.post(`/api/auth/userPassLogin${this.account.query || ''}`)
|
||||
.set('referer', 'https://www.luogu.com.cn/user/setting')
|
||||
.send({
|
||||
username: this.account.handle,
|
||||
password: this.account.password,
|
||||
});
|
||||
if (res.headers['set-cookie']) this.setCookie(res.headers['set-cookie']);
|
||||
if (await this.loggedIn) {
|
||||
await this.getCsrfToken('/user/setting');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user