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