fixed logout / login

This commit is contained in:
maru21 2023-10-28 20:36:11 +02:00
parent e08e3e4bbd
commit a39c16e54b
6 changed files with 53 additions and 19 deletions

View File

@ -313,7 +313,7 @@
style="display: none"
>
<span
onclick="this.parentElement.style.display='none'"
onclick="this.parentElement.style.display='block'"
class="w3-button w3-display-topright"
>&times;</span
>
@ -322,7 +322,6 @@
<a
href="#"
style="text-decoration: underline"
onclick="localStorage.clear()"
>clear</a
>
all files?

View File

@ -55,6 +55,7 @@ function init() {
try {
window.localStorage.getItem("test")
} catch (e) {
console.log("localStorage not available");
activeState.settings.persistentStorage = "false";
}
@ -76,12 +77,13 @@ function init() {
//load settings from storage
let settings = storeSettings("getInit", true);
if (settings != "") {
if (settings != null) {
for (let setting of Object.entries(settings)) {
activeState.settings[setting[0]] = setting[1];
}
}
//load NavigationBar with templates according to server
loadNavBar();

View File

@ -1,4 +1,4 @@
import { createStorageObj, retrieveData } from "./storage.js";
import { clearStorage, createStorageObj, retrieveData } from "./storage.js";
import sha256 from "./sha256.min.js";
import XORCipher from "./xorc.js";
import getBrowserFingerprint from "./identify.js"
@ -7,29 +7,42 @@ export const passwordHash = {
name: cyrb53("m21_"+getBrowserFingerprint( { hardwareOnly: true } )),
toString: function () {
let token = window.activeState.sessionToken;
if (token == null || token == "") return "none";
if (token == null) return "";
if (token == "") return "";
return XORCipher.decode(this.name, token);
},
set: function (pw) {
activeState.sessionToken = XORCipher.encode(this.name, pw);
},
init: function () {
//check if cookie exists
if (getCookie(sha256(this.name)) != null) {
this.set(XORCipher.decode(sha256(this.name), getCookie(sha256(this.name))));
if (getCookie(sha256(this.name)) != "") {
this.set(XORCipher.decode(sha256(this.name), getCookie(sha256(this.name))));
}
}
if (passwordHash == "") {
return;
}
let verifiedStatus = false;
let tF = retrieveData("templateFiles");
if (tF != null) {verifiedStatus = true}
if (verifiedStatus == true) {
setCookie(sha256(this.name), XORCipher.encode(sha256(this.name), this), 10);
}
},
verify: function () {
if (passwordHash == "") {
return false;
}
let verifiedStatus = false;
let tF = retrieveData("templateFiles");
if (tF != null) {verifiedStatus = true}
if (tF != null) {
verifiedStatus = true
}
return verifiedStatus;
}
}
@ -43,16 +56,28 @@ function setPassword() {
passwordHash.set(sha256(pw));
let templateFiles = retrieveData("templateFiles");
if (templateFiles == null) {
document.getElementById("wrongPWAlert").style.display = "block";
const alertTimeout = setTimeout(() => {
document.getElementById("wrongPWAlert").style.display = "none";
}, 5000);
let wrongPWAlert = document.getElementById("wrongPWAlert");
wrongPWAlert.style.display = "block";
wrongPWAlert.addEventListener("click", (e) => {
if (e.target && e.target.tagName === "A") {
clearStorage();
document.getElementById("wrongPWAlert").innerHTML =
"<p>all files cleared - set new password</p>";
}
});
passwordHash.set(pwOld);
x.elements[0].value = "";
return;
}
//user logged in
//make sure to bring back persistent stat after logout
activeState.settings.persistentStorage = "true";
let tF = retrieveData("templateFiles");
if (tF == null || tF.length == 0) {
activeState.settings.persistentStorage = "false";
}
document.getElementById("login").style.display = "none";
setCookie(sha256(passwordHash.name), XORCipher.encode(sha256(passwordHash.name), passwordHash), 10)
}

View File

@ -1,7 +1,6 @@
import { hideMenus, modalNotifier, printVersion, resetNavBar } from "./evts.js";
import { passwordHash, sanitize } from "./scripts.js";
import sha256 from "./sha256.min.js";
import { retrieveData, storeData, storeSettings } from "./storage.js";
import { clearData, retrieveData, storeData, storeSettings } from "./storage.js";
const buildSettings = () => {
//set current page value in activeState object
@ -185,16 +184,14 @@ function saveSettings() {
if (setting[0] == "persistentStorage") {
let tF = retrieveData("templateFiles");
let settings = storeSettings("get", true);
storeSettings(obj);
activeState.settings[setting[0]] = setting[1];
if (setting[1] == "false") {
try {
window.localStorage.removeItem(sha256("settings_m21_"));
} catch (e) {}
let msg = (activeState.settings.persistentStorage == "false") ? "temporary" : "persistent";
printVersion("storage mode: "+msg+" |");
}
if (settings != "") storeSettings(settings);
if (settings != "") storeSettings(obj);
if (tF != null) storeData("templateFiles", tF);
}
}

View File

@ -133,6 +133,9 @@ function clearData(name, template = "none") {
lT = template;
key = sha256(name + "_m21_" + template);
}
if (name == "templateFiles") {
key = sha256(name + "_m21_");
}
store.removeItem(key);
}
@ -176,6 +179,7 @@ function getFileName(ref = "none") {
}
function obfuscate(data, mode = true) {
if (data == null | data == "") return "";
if (mode) {
return XORCipher.encode(sha256(passwordHash), data);
} else {
@ -271,6 +275,10 @@ function storeSettings(data, get = false) {
}
}
function clearStorage() {
store.clear();
}
export {
createStorageObj,
storeData,
@ -280,4 +288,5 @@ export {
createBookShelf,
importBookShelf,
storeSettings,
clearStorage
};

View File

@ -48,8 +48,10 @@ function loadTemplate(template, newFlag = false, loadOnly = false) {
} else {
cdata = retrieveData("userInputForce");
}
if (cdata != "" || cdata == null) {
retrieveForm(cdata);
if (cdata != "") {
if (cdata == null) {
retrieveForm(cdata);
}
}
//select first object and focus on it