Stephan Richter
3 months ago
5 changed files with 46 additions and 27 deletions
@ -1,27 +1,34 @@
@@ -1,27 +1,34 @@
|
||||
var user = null; |
||||
async function handleUser(response){ |
||||
|
||||
function handleUser(response){ |
||||
if (response.status == UNAUTHORIZED) { |
||||
login(); |
||||
return; |
||||
} |
||||
if (response.ok){ |
||||
user = await response.json(); |
||||
fetch(web+"/navigation.html").then(handleNavigation); |
||||
response.json().then(u => { |
||||
user = u; |
||||
fetch(web+"/navigation.html",{credentials:'include'}).then(handleNavigation); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
async function handleNavigation(response){ |
||||
function handleNavigation(response){ |
||||
if (response.ok){ |
||||
var content = await response.text(); |
||||
var nav = document.getElementsByTagName('nav')[0]; |
||||
nav.innerHTML = content; |
||||
var links = nav.getElementsByTagName('a'); |
||||
for (var index = links.length; index > 0; index--){ |
||||
var link = links[index-1]; |
||||
var clazz = link.hasAttribute('class') ? link.getAttribute("class") : null; |
||||
if (clazz != null && !user.permissions.includes(clazz)) nav.removeChild(link); |
||||
} |
||||
response.text().then(content => { |
||||
var nav = document.getElementsByTagName('nav')[0]; |
||||
nav.innerHTML = content; |
||||
var links = nav.getElementsByTagName('a'); |
||||
for (var index = links.length; index > 0; index--){ |
||||
var link = links[index-1]; |
||||
var clazz = link.hasAttribute('class') ? link.getAttribute("class") : null; |
||||
if (clazz != null && !user.permissions.includes(clazz)) nav.removeChild(link); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
|
||||
fetch(user_controller+"/",{method:'POST'}).then(handleUser); |
||||
fetch(user_controller+"/",{ |
||||
method:'POST', |
||||
credentials:'include' |
||||
}).then(handleUser); |
||||
|
Loading…
Reference in new issue