started with cookie implementation
This commit is contained in:
parent
a223e8e8cb
commit
1d711542da
@ -8,18 +8,6 @@ function createTemplate(template = false) {
|
|||||||
//set current page value in activeState object
|
//set current page value in activeState object
|
||||||
activeState.activePage = "createTemplate";
|
activeState.activePage = "createTemplate";
|
||||||
|
|
||||||
//check if user is authenticated and templateFilesArray is decryptable
|
|
||||||
let tF = retrieveData("templateFiles");
|
|
||||||
if (tF != "") {
|
|
||||||
try {
|
|
||||||
tF = JSON.parse(tF);
|
|
||||||
} catch (e) {
|
|
||||||
alert("Decryption failed; are you authenticated?");
|
|
||||||
window.location.reload();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (screen.width > 992) {
|
if (screen.width > 992) {
|
||||||
document.getElementById("siteTitle").innerHTML = "Manage templates";
|
document.getElementById("siteTitle").innerHTML = "Manage templates";
|
||||||
|
|||||||
@ -14,17 +14,8 @@ function buildFile() {
|
|||||||
//set current page value in activeState object
|
//set current page value in activeState object
|
||||||
activeState.activePage = "files";
|
activeState.activePage = "files";
|
||||||
|
|
||||||
//check if user is authenticated and templateFilesArray is decryptable
|
//set templateFiles array
|
||||||
let tF = retrieveData("templateFiles");
|
let tF = JSON.parse(retrieveData("templateFiles"));
|
||||||
if (tF != "") {
|
|
||||||
try {
|
|
||||||
tF = JSON.parse(tF);
|
|
||||||
} catch (e) {
|
|
||||||
alert("Decryption failed; are you authenticated?");
|
|
||||||
window.location.reload();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tF == null) {
|
if (tF == null) {
|
||||||
//console.log("none yet");
|
//console.log("none yet");
|
||||||
|
|||||||
@ -78,6 +78,48 @@ export function getUsrId() {
|
|||||||
return cyrb53(fingerprint + passwordHash);
|
return cyrb53(fingerprint + passwordHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sessionVerification() {
|
||||||
|
let verfiedStatus = window.sessionStorage.getItem(sha256("verified"));
|
||||||
|
if (verfiedStatus == '') {verfiedStatus = null}
|
||||||
|
if (verfiedStatus != null) {
|
||||||
|
//user logged in
|
||||||
|
|
||||||
|
//write verifiedStatus content into passwordHash for decode check later
|
||||||
|
//passwordHash.set(XORCipher.decode(sha256("passwordHash"), verfiedStatus));
|
||||||
|
//document.getElementById("login").style.display = "none";
|
||||||
|
//load NavigationBar with templates according to server
|
||||||
|
|
||||||
|
let data;
|
||||||
|
try {
|
||||||
|
data = window.sessionStorage.getItem(sha256(passwordHash.name));
|
||||||
|
} catch (e) {
|
||||||
|
verfiedStatus = null;
|
||||||
|
}
|
||||||
|
if (data === null) verfiedStatus = null;
|
||||||
|
|
||||||
|
let tF = retrieveData("templateFiles");
|
||||||
|
try {
|
||||||
|
tF = JSON.parse(tF);
|
||||||
|
} catch(e) {
|
||||||
|
verfiedStatus = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//check if cookie exists
|
||||||
|
if (getCookie(sha256("verified")) != null) {
|
||||||
|
//passwordHash.set(XORCipher.decode(sha256("passwordHash"), getCookie(sha256("verified"))));
|
||||||
|
//document.getElementById("login").style.display = "none";
|
||||||
|
//load NavigationBar with templates according to server
|
||||||
|
//initweb();
|
||||||
|
} else {
|
||||||
|
//document.getElementById("login").style.display = "block";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (verfiedStatus == null) window.stop();
|
||||||
|
console.log('v: ',verfiedStatus);
|
||||||
|
}
|
||||||
|
|
||||||
const cyrb53 = (str, seed = 21) => {
|
const cyrb53 = (str, seed = 21) => {
|
||||||
let h1 = 0xdeadbeef ^ seed,
|
let h1 = 0xdeadbeef ^ seed,
|
||||||
h2 = 0x41c6ce57 ^ seed;
|
h2 = 0x41c6ce57 ^ seed;
|
||||||
@ -93,4 +135,26 @@ const cyrb53 = (str, seed = 21) => {
|
|||||||
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function setCookie(cname, cvalue, exdays) {
|
||||||
|
const d = new Date();
|
||||||
|
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
||||||
|
let expires = "expires="+d.toUTCString();
|
||||||
|
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCookie(cname) {
|
||||||
|
let name = cname + "=";
|
||||||
|
let ca = document.cookie.split(';');
|
||||||
|
for(let i = 0; i < ca.length; i++) {
|
||||||
|
let c = ca[i];
|
||||||
|
while (c.charAt(0) == ' ') {
|
||||||
|
c = c.substring(1);
|
||||||
|
}
|
||||||
|
if (c.indexOf(name) == 0) {
|
||||||
|
return c.substring(name.length, c.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export default setPassword;
|
export default setPassword;
|
||||||
|
|||||||
@ -120,16 +120,13 @@ function getFileName() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let lT = activeState.loadedTemplate;
|
let lT = activeState.loadedTemplate;
|
||||||
let tF = retrieveData("templateFiles");
|
let tF = null;
|
||||||
if (tF != "") {
|
|
||||||
try {
|
try {
|
||||||
tF = JSON.parse(tF);
|
tF = JSON.parse(retrieveData("templateFiles"));
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
alert("Decryption failed; are you authenticated?");
|
tF = null;
|
||||||
window.location.reload();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tF != null) {
|
if (tF != null) {
|
||||||
for (let tFi of tF) {
|
for (let tFi of tF) {
|
||||||
if (tFi.fileName == currentFileName) {return currentFileName};
|
if (tFi.fileName == currentFileName) {return currentFileName};
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { loadFileDivCallBack } from "./files.js";
|
|||||||
import { retrieveData, clearData, getFileName, importBookShelf } from "./storage.js";
|
import { retrieveData, clearData, getFileName, importBookShelf } from "./storage.js";
|
||||||
import { insertTextBlocks } from "./evts.js";
|
import { insertTextBlocks } from "./evts.js";
|
||||||
import { createTemplate, createTemplateCallBack} from "./createTemplate.js";
|
import { createTemplate, createTemplateCallBack} from "./createTemplate.js";
|
||||||
import { getUsrId } from "./scripts.js";
|
import { getUsrId, sessionVerification } from "./scripts.js";
|
||||||
|
|
||||||
function loadTemplate(template, newFlag = false, loadOnly = false) {
|
function loadTemplate(template, newFlag = false, loadOnly = false) {
|
||||||
document.getElementById("siteTitle").innerHTML = template.replace(/_/g, " ");
|
document.getElementById("siteTitle").innerHTML = template.replace(/_/g, " ");
|
||||||
@ -70,6 +70,10 @@ function loadTemplate(template, newFlag = false, loadOnly = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadNewTemplate(template) {
|
function loadNewTemplate(template) {
|
||||||
|
|
||||||
|
//sessionVerfication check
|
||||||
|
sessionVerification();
|
||||||
|
|
||||||
//set current page value in activeState object
|
//set current page value in activeState object
|
||||||
activeState.activePage = "template";
|
activeState.activePage = "template";
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user