improve(webui): Handle nonce being invalidated by client logging in (#239)

This commit is contained in:
Sainan 2024-05-29 16:19:41 +02:00 committed by GitHub
parent b1e0de862f
commit 5f2adb7b47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,24 @@ function doLogin() {
}
function loginFromLocalStorage() {
doLoginRequest(
data => {
if (single.getCurrentPath() == "/webui/") {
single.loadRoute("/webui/inventory");
}
$(".displayname").text(data.DisplayName);
window.accountId = data.id;
window.authz = "accountId=" + data.id + "&nonce=" + data.Nonce;
updateInventory();
},
() => {
logout();
alert("Login failed");
}
);
}
function doLoginRequest(succ_cb, fail_cb) {
const req = $.post({
url: "/api/login.php",
contentType: "text/plain",
@ -20,19 +38,22 @@ function loginFromLocalStorage() {
PS: "W0RFXVN0ZXZlIGxpa2VzIGJpZyBidXR0cw==" // anti-cheat data
})
});
req.done(data => {
if (single.getCurrentPath() == "/webui/") {
single.loadRoute("/webui/inventory");
req.done(succ_cb);
req.fail(fail_cb);
}
$(".displayname").text(data.DisplayName);
window.accountId = data.id;
function revalidateAuthz(succ_cb) {
return doLoginRequest(
data => {
window.authz = "accountId=" + data.id + "&nonce=" + data.Nonce;
updateInventory();
});
req.fail(() => {
succ_cb();
},
() => {
logout();
alert("Login failed");
});
alert("Your credentials are no longer valid.");
single.loadRoute("/webui/"); // Show login screen
}
);
}
function logout() {
@ -176,6 +197,7 @@ function doAcquireWarframe() {
$("#warframe-to-acquire").addClass("is-invalid").focus();
return;
}
revalidateAuthz(() => {
const req = $.post({
url: "/custom/addItem",
contentType: "application/json",
@ -189,6 +211,7 @@ function doAcquireWarframe() {
document.getElementById("warframe-to-acquire").value = "";
updateInventory();
});
});
}
$("#warframe-to-acquire").on("input", () => {
@ -201,6 +224,7 @@ function doAcquireWeapon() {
$("#weapon-to-acquire").addClass("is-invalid").focus();
return;
}
revalidateAuthz(() => {
const req = $.post({
url: "/custom/addItem",
contentType: "application/json",
@ -214,6 +238,7 @@ function doAcquireWeapon() {
document.getElementById("weapon-to-acquire").value = "";
updateInventory();
});
});
}
$("#weapon-to-acquire").on("input", () => {
@ -228,6 +253,7 @@ function addGearExp(category, oid, xp) {
XP: xp
}
];
revalidateAuthz(() => {
$.post({
url: "/api/missionInventoryUpdate.php?" + window.authz,
contentType: "text/plain",
@ -235,6 +261,7 @@ function addGearExp(category, oid, xp) {
}).done(function () {
updateInventory();
});
});
}
function disposeOfGear(category, oid) {
@ -248,6 +275,7 @@ function disposeOfGear(category, oid) {
String: oid
}
];
revalidateAuthz(() => {
$.post({
url: "/api/sell.php?" + window.authz,
contentType: "text/plain",
@ -255,6 +283,7 @@ function disposeOfGear(category, oid) {
}).done(function () {
updateInventory();
});
});
}
function doAcquireMiscItems() {
@ -263,6 +292,7 @@ function doAcquireMiscItems() {
$("#miscitem-type").addClass("is-invalid").focus();
return;
}
revalidateAuthz(() => {
$.post({
url: "/api/missionInventoryUpdate.php?" + window.authz,
contentType: "text/plain",
@ -277,6 +307,7 @@ function doAcquireMiscItems() {
}).done(function () {
alert("Successfully added.");
});
});
}
$("#miscitem-name").on("input", () => {
@ -301,6 +332,7 @@ function doAcquireRiven() {
return;
}
const uniqueName = "/Lotus/Upgrades/Mods/Randomized/" + $("#addriven-type").val();
revalidateAuthz(() => {
// Add riven type to inventory
$.post({
url: "/api/missionInventoryUpdate.php?" + window.authz,
@ -340,6 +372,7 @@ function doAcquireRiven() {
}
});
});
});
}
$("#addriven-fingerprint").on("input", () => {