forked from OpenWF/SpaceNinjaServer
improve(webui): Handle nonce being invalidated by client logging in (#239)
This commit is contained in:
parent
b1e0de862f
commit
5f2adb7b47
@ -6,6 +6,24 @@ function doLogin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loginFromLocalStorage() {
|
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({
|
const req = $.post({
|
||||||
url: "/api/login.php",
|
url: "/api/login.php",
|
||||||
contentType: "text/plain",
|
contentType: "text/plain",
|
||||||
@ -20,19 +38,22 @@ function loginFromLocalStorage() {
|
|||||||
PS: "W0RFXVN0ZXZlIGxpa2VzIGJpZyBidXR0cw==" // anti-cheat data
|
PS: "W0RFXVN0ZXZlIGxpa2VzIGJpZyBidXR0cw==" // anti-cheat data
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
req.done(data => {
|
req.done(succ_cb);
|
||||||
if (single.getCurrentPath() == "/webui/") {
|
req.fail(fail_cb);
|
||||||
single.loadRoute("/webui/inventory");
|
}
|
||||||
|
|
||||||
|
function revalidateAuthz(succ_cb) {
|
||||||
|
return doLoginRequest(
|
||||||
|
data => {
|
||||||
|
window.authz = "accountId=" + data.id + "&nonce=" + data.Nonce;
|
||||||
|
succ_cb();
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
logout();
|
||||||
|
alert("Your credentials are no longer valid.");
|
||||||
|
single.loadRoute("/webui/"); // Show login screen
|
||||||
}
|
}
|
||||||
$(".displayname").text(data.DisplayName);
|
);
|
||||||
window.accountId = data.id;
|
|
||||||
window.authz = "accountId=" + data.id + "&nonce=" + data.Nonce;
|
|
||||||
updateInventory();
|
|
||||||
});
|
|
||||||
req.fail(() => {
|
|
||||||
logout();
|
|
||||||
alert("Login failed");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
@ -176,18 +197,20 @@ function doAcquireWarframe() {
|
|||||||
$("#warframe-to-acquire").addClass("is-invalid").focus();
|
$("#warframe-to-acquire").addClass("is-invalid").focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const req = $.post({
|
revalidateAuthz(() => {
|
||||||
url: "/custom/addItem",
|
const req = $.post({
|
||||||
contentType: "application/json",
|
url: "/custom/addItem",
|
||||||
data: JSON.stringify({
|
contentType: "application/json",
|
||||||
type: "Powersuit",
|
data: JSON.stringify({
|
||||||
internalName: uniqueName,
|
type: "Powersuit",
|
||||||
accountId: window.accountId
|
internalName: uniqueName,
|
||||||
})
|
accountId: window.accountId
|
||||||
});
|
})
|
||||||
req.done(() => {
|
});
|
||||||
document.getElementById("warframe-to-acquire").value = "";
|
req.done(() => {
|
||||||
updateInventory();
|
document.getElementById("warframe-to-acquire").value = "";
|
||||||
|
updateInventory();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,18 +224,20 @@ function doAcquireWeapon() {
|
|||||||
$("#weapon-to-acquire").addClass("is-invalid").focus();
|
$("#weapon-to-acquire").addClass("is-invalid").focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const req = $.post({
|
revalidateAuthz(() => {
|
||||||
url: "/custom/addItem",
|
const req = $.post({
|
||||||
contentType: "application/json",
|
url: "/custom/addItem",
|
||||||
data: JSON.stringify({
|
contentType: "application/json",
|
||||||
type: "Weapon",
|
data: JSON.stringify({
|
||||||
internalName: uniqueName,
|
type: "Weapon",
|
||||||
accountId: window.accountId
|
internalName: uniqueName,
|
||||||
})
|
accountId: window.accountId
|
||||||
});
|
})
|
||||||
req.done(() => {
|
});
|
||||||
document.getElementById("weapon-to-acquire").value = "";
|
req.done(() => {
|
||||||
updateInventory();
|
document.getElementById("weapon-to-acquire").value = "";
|
||||||
|
updateInventory();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,12 +253,14 @@ function addGearExp(category, oid, xp) {
|
|||||||
XP: xp
|
XP: xp
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
$.post({
|
revalidateAuthz(() => {
|
||||||
url: "/api/missionInventoryUpdate.php?" + window.authz,
|
$.post({
|
||||||
contentType: "text/plain",
|
url: "/api/missionInventoryUpdate.php?" + window.authz,
|
||||||
data: JSON.stringify(data)
|
contentType: "text/plain",
|
||||||
}).done(function () {
|
data: JSON.stringify(data)
|
||||||
updateInventory();
|
}).done(function () {
|
||||||
|
updateInventory();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,12 +275,14 @@ function disposeOfGear(category, oid) {
|
|||||||
String: oid
|
String: oid
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
$.post({
|
revalidateAuthz(() => {
|
||||||
url: "/api/sell.php?" + window.authz,
|
$.post({
|
||||||
contentType: "text/plain",
|
url: "/api/sell.php?" + window.authz,
|
||||||
data: JSON.stringify(data)
|
contentType: "text/plain",
|
||||||
}).done(function () {
|
data: JSON.stringify(data)
|
||||||
updateInventory();
|
}).done(function () {
|
||||||
|
updateInventory();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,19 +292,21 @@ function doAcquireMiscItems() {
|
|||||||
$("#miscitem-type").addClass("is-invalid").focus();
|
$("#miscitem-type").addClass("is-invalid").focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$.post({
|
revalidateAuthz(() => {
|
||||||
url: "/api/missionInventoryUpdate.php?" + window.authz,
|
$.post({
|
||||||
contentType: "text/plain",
|
url: "/api/missionInventoryUpdate.php?" + window.authz,
|
||||||
data: JSON.stringify({
|
contentType: "text/plain",
|
||||||
MiscItems: [
|
data: JSON.stringify({
|
||||||
{
|
MiscItems: [
|
||||||
ItemType: uniqueName,
|
{
|
||||||
ItemCount: $("#miscitem-count").val()
|
ItemType: uniqueName,
|
||||||
}
|
ItemCount: $("#miscitem-count").val()
|
||||||
]
|
}
|
||||||
})
|
]
|
||||||
}).done(function () {
|
})
|
||||||
alert("Successfully added.");
|
}).done(function () {
|
||||||
|
alert("Successfully added.");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,43 +332,45 @@ function doAcquireRiven() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const uniqueName = "/Lotus/Upgrades/Mods/Randomized/" + $("#addriven-type").val();
|
const uniqueName = "/Lotus/Upgrades/Mods/Randomized/" + $("#addriven-type").val();
|
||||||
// Add riven type to inventory
|
revalidateAuthz(() => {
|
||||||
$.post({
|
// Add riven type to inventory
|
||||||
url: "/api/missionInventoryUpdate.php?" + window.authz,
|
$.post({
|
||||||
contentType: "text/plain",
|
url: "/api/missionInventoryUpdate.php?" + window.authz,
|
||||||
data: JSON.stringify({
|
contentType: "text/plain",
|
||||||
RawUpgrades: [
|
data: JSON.stringify({
|
||||||
{
|
RawUpgrades: [
|
||||||
ItemType: uniqueName,
|
{
|
||||||
ItemCount: 1
|
ItemType: uniqueName,
|
||||||
|
ItemCount: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}).done(function () {
|
||||||
|
// Get riven's assigned id
|
||||||
|
$.get("/api/inventory.php?" + window.authz).done(data => {
|
||||||
|
for (const rawUpgrade of data.RawUpgrades) {
|
||||||
|
if (rawUpgrade.ItemType === uniqueName) {
|
||||||
|
// Add fingerprint to riven
|
||||||
|
$.post({
|
||||||
|
url: "/api/artifacts.php?" + window.authz,
|
||||||
|
contentType: "text/plain",
|
||||||
|
data: JSON.stringify({
|
||||||
|
Upgrade: {
|
||||||
|
ItemType: uniqueName,
|
||||||
|
UpgradeFingerprint: JSON.stringify(fingerprint),
|
||||||
|
ItemId: rawUpgrade.LastAdded
|
||||||
|
},
|
||||||
|
LevelDiff: 0,
|
||||||
|
Cost: 0,
|
||||||
|
FusionPointCost: 0
|
||||||
|
})
|
||||||
|
}).done(function () {
|
||||||
|
alert("Successfully added.");
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
});
|
||||||
})
|
|
||||||
}).done(function () {
|
|
||||||
// Get riven's assigned id
|
|
||||||
$.get("/api/inventory.php?" + window.authz).done(data => {
|
|
||||||
for (const rawUpgrade of data.RawUpgrades) {
|
|
||||||
if (rawUpgrade.ItemType === uniqueName) {
|
|
||||||
// Add fingerprint to riven
|
|
||||||
$.post({
|
|
||||||
url: "/api/artifacts.php?" + window.authz,
|
|
||||||
contentType: "text/plain",
|
|
||||||
data: JSON.stringify({
|
|
||||||
Upgrade: {
|
|
||||||
ItemType: uniqueName,
|
|
||||||
UpgradeFingerprint: JSON.stringify(fingerprint),
|
|
||||||
ItemId: rawUpgrade.LastAdded
|
|
||||||
},
|
|
||||||
LevelDiff: 0,
|
|
||||||
Cost: 0,
|
|
||||||
FusionPointCost: 0
|
|
||||||
})
|
|
||||||
}).done(function () {
|
|
||||||
alert("Successfully added.");
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user