From 72edc65864ba55804865f7702446e715cec5256c Mon Sep 17 00:00:00 2001 From: Wolfgang Knopki <wolfgang.knopki@hft-stuttgart.de> Date: Tue, 22 Oct 2019 15:07:45 +0200 Subject: [PATCH] test dynamic header --- js/headfoot.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/js/headfoot.js b/js/headfoot.js index a1aecda..cf861a4 100755 --- a/js/headfoot.js +++ b/js/headfoot.js @@ -10,7 +10,6 @@ function prependChild(parent,child){ parent.insertBefore(child, parent.childNodes[0]); } - console.log(document.getElementById('loginswitch').getAttribute('authenticated')); function userAuthenticated(){ let params = new URLSearchParams(window.location.search); if(params.get('isAuthenticatedUser')){ @@ -21,6 +20,18 @@ function userAuthenticated(){ return false; } } + + +function sendRequest(URL){ + let xhr = new XMLHttpRequest(); + xhr.open("POST", URL, true); + let token = $("meta[name='_csrf']").attr("content"); + //Send the proper header information along with the request + xhr.setRequestHeader('X-CSRF-TOKEN', token); + xhr.send(); +} + + /* function head() * creates header and prepends it to the documents body */ @@ -95,7 +106,8 @@ function head(){ headlink.innerHTML="Account"; headlink.href="/account/"; }else if(document.getElementById('loginswitch').getAttribute('authenticated') == '2'){ - headlink.href="./logout"; + headlink.onclick="sendRequest('./logout');"; + headlink.href="#"; headlink.innerHTML="Logout"; } -- GitLab