add csrf token saving

This commit is contained in:
Arthur Lu 2022-12-15 23:15:52 -08:00
parent 22f334f373
commit 7618b24898
2 changed files with 3 additions and 2 deletions

View File

@ -13,7 +13,7 @@ function init (){
try {
status.innerText = "Authenticating...";
let ticket = await requestTicket(formData.get("username"), formData.get("password"));
setTicket(ticket.data.ticket);
setTicket(ticket.data.ticket, ticket.data.CSRFPreventionToken);
window.location.href = "index.html";
}
catch (error) {

View File

@ -18,10 +18,11 @@ export async function requestTicket (username, password) {
return response;
}
export function setTicket (ticket) {
export function setTicket (ticket, csrf) {
let d = new Date();
d.setTime(d.getTime() + (2*60*60*1000));
document.cookie = `PVEAuthCookie=${ticket}; path=/; expires=${d.toUTCString()}; domain=.tronnet.net`;
document.cookie = `CSRFPreventionToken=${csrf}; path=/; expires=${d.toUTCString()}; domain=.tronnet.net;`
}
export async function request (path, method, body = null, auth = true) {