vjudge: luogu: fix login

pull/499/head
undefined 2 years ago
parent 1f585968a4
commit bc43b2fd4e

@ -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;
}

Loading…
Cancel
Save