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