test UserInfo
This commit is contained in:
parent
356b99b7ca
commit
7a7321f69d
@ -1,14 +1,12 @@
|
||||
let UserInfo;
|
||||
const toggleButton = document.getElementById("toggle_button")
|
||||
const navLinks = document.getElementById("navsite_list")
|
||||
|
||||
toggleButton.addEventListener('click', () => {
|
||||
navLinks.classList.toggle("active")
|
||||
})
|
||||
|
||||
|
||||
let UserInfo;
|
||||
|
||||
async function handleResponse(data, successMessage, failureMessage) {
|
||||
async
|
||||
function handleResponse(data, successMessage, failureMessage) {
|
||||
const statusMessageContainer = document.getElementById("statusMessageContainer");
|
||||
|
||||
const statusMessage = document.createElement("div");
|
||||
@ -34,7 +32,8 @@ async function handleResponse(data, successMessage, failureMessage) {
|
||||
}
|
||||
|
||||
async function showDashboardGreeting() {
|
||||
document.getElementById("welcomeMsg").innerText = `Ahoj, ${UserInfo.FirstName}.`;
|
||||
let FirstName = localStorage.getItem("FirstName");
|
||||
document.getElementById("welcomeMsg").innerText = `Ahoj, ${FirstName}.`;
|
||||
}
|
||||
|
||||
async function doAction(url, requestData, successMessage, failureMessage, silent = false) {
|
||||
@ -162,6 +161,7 @@ async function initAjax() {
|
||||
document.addEventListener('DOMContentLoaded', initAjax);
|
||||
|
||||
async function onPageLoad(){
|
||||
await restoreUserInfo();
|
||||
let currentSite = localStorage.getItem("currentSite");
|
||||
let currentPage = localStorage.getItem("currentPage");
|
||||
if(currentSite === "home" && currentPage === "settings"){
|
||||
@ -213,6 +213,7 @@ async function logout() {
|
||||
|
||||
doAction('/account', data, "Logout Successful!", "Logout failed.")
|
||||
.then(async () => {
|
||||
localStorage.clear();
|
||||
await refreshNavbar();
|
||||
await navigateTo(localStorage.getItem("defaultSite"), localStorage.getItem("defaultPage"));
|
||||
umami.track("logout");
|
||||
@ -325,6 +326,16 @@ async function populateUserInfoFields(userData) {
|
||||
document.getElementById("updateNewEmail").value = userData.Email || "";
|
||||
}
|
||||
|
||||
async function restoreUserInfo(){
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
let key = localStorage.key(i);
|
||||
if (key.startsWith("UserInfo_")){
|
||||
let keyClean = key.replace("UserInfo_", "");
|
||||
UserInfo[keyClean] = localStorage.getItem(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function getUserInfo() {
|
||||
const data = {
|
||||
action: "get_user_info",
|
||||
@ -333,6 +344,9 @@ async function getUserInfo() {
|
||||
doAction('/account', data, "User info retrieved Successfully!", "User info retrieval failed.", true) .then((result) => {
|
||||
if (result && result.Status === "Success") {
|
||||
UserInfo = result.UserInfo;
|
||||
UserInfo.forEach(function callback(value, index) {
|
||||
localStorage.setItem("UserInfo_" + index, value);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
14
lib/page.php
14
lib/page.php
@ -136,13 +136,23 @@ function getPage($site_name_in = null, $page_name_in = null): string
|
||||
$page_title = $page_name;
|
||||
}
|
||||
$dynamic_style = doDynamicStyling();
|
||||
$dynamic_script = generateScriptData([
|
||||
$dynamic_script_data = [
|
||||
"currentPage" => $page_name,
|
||||
"currentSite" => $site_name,
|
||||
"currentTitle" => $page_title,
|
||||
"defaultPage" => $routerConfig["default_page"],
|
||||
"defaultSite" => $routerConfig["default_site"],
|
||||
]);
|
||||
];
|
||||
if(isLoggedIn()){
|
||||
$dynamic_script_data += [
|
||||
"UserInfo_FirstName" => $_SESSION["FirstName"],
|
||||
"UserInfo_LastName" => $_SESSION["LastName"],
|
||||
"UserInfo_Nickname" => $_SESSION["Nickname"],
|
||||
"UserInfo_Email" => $_SESSION["Email"],
|
||||
"UserInfo_MinecraftNick" => $_SESSION["MinecraftNick"],
|
||||
];
|
||||
}
|
||||
$dynamic_script = generateScriptData($dynamic_script_data);
|
||||
|
||||
$navigation = generateNavigation();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user