fix user name by adding username cookie

This commit is contained in:
Arthur Lu 2023-02-14 05:21:45 +00:00
parent eb26054c74
commit 139bc324e8
3 changed files with 6 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import {requestPVE, goToPage, instances} from "./utils.js";
import {requestPVE, goToPage, instances, getCookie} from "./utils.js";
export class Instance extends HTMLElement {
constructor () {
@ -131,7 +131,7 @@ export class Instance extends HTMLElement {
handleConsoleButton () {
if (this.status === "running") {
goToPage("pve-xtermjs/index.html", {type: this.type, vmid: this.vmid, name: this.name, node: this.node.name, user: "alu@ldap", url: "pve.tronnet.net/api2/json"});
goToPage("pve-xtermjs/index.html", {type: this.type, vmid: this.vmid, name: this.name, node: this.node.name, user: getCookie("username"), url: "pve.tronnet.net/api2/json"});
}
}
}

View File

@ -14,7 +14,7 @@ function init (){
try {
status.innerText = "Authenticating...";
let ticket = await requestTicket(formData.get("username"), formData.get("password"));
setTicket(ticket.data.ticket, ticket.data.CSRFPreventionToken);
setTicket(ticket.data.ticket, ticket.data.CSRFPreventionToken, formData.get("username"));
status.innerText = "Authentication successful!"
status.style.color = "#00ff00";
goToPage("index.html");

View File

@ -59,7 +59,7 @@ export const instances = {
}
}
function getCookie(cname) {
export function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(";");
@ -81,11 +81,12 @@ export async function requestTicket (username, password) {
return response;
}
export function setTicket (ticket, csrf) {
export function setTicket (ticket, csrf, username) {
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;`
document.cookie = `username=${username}@ldap; path=/; expires=${d.toUTCString()}; domain=.tronnet.net;`
}
export async function requestPVE (path, method, body = null) {