implemented cookies, implemented local file delivery option (--base /path/to/static/content), refactoring static files

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-07-19 23:39:32 +02:00
parent 59075db1ad
commit 9ee963924d
13 changed files with 124 additions and 77 deletions

View File

@@ -2,10 +2,7 @@
<head>
<title>Light OIDC</title>
<script src="config.js"></script>
<script src="lightoidc.js"></script>
<script>
checkUser();
</script>
<script src="index.js"></script>
</head>
<body>
<h1>Welcome!</h1>

View File

@@ -0,0 +1,7 @@
const UNAUTHORIZED = 401;
function handleUser(response){
console.log(response);
}
fetch(api+"/user").then(handleUser);

View File

@@ -1,43 +0,0 @@
const UNAUTHORIZED = 401;
function handleCheckUser(response){
console.log(window.location.href);
if (response.status == UNAUTHORIZED){
window.location.href = "login.html";
return;
}
}
function checkUser(){
fetch(api+"/user")
.then(handleCheckUser)
.catch((err) => console.log(err));
}
function handleLogin(response){
if (response.status == 401){
loadError("login-failed");
return;
}
console.log(response);
}
function loadError(page){
fetch(web+"/"+page+".txt").then(resp => resp.text()).then(showError);
}
function showError(content){
document.getElementById("error").innerHTML = content;
}
function tryLogin(){
document.getElementById("error").innerHTML = "";
var data = Object.fromEntries(new FormData(document.getElementById('login')));
fetch(api+"/login",{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(handleLogin);
}

View File

@@ -2,7 +2,7 @@
<head>
<title>Light OIDC</title>
<script src="config.js"></script>
<script src="lightoidc.js"></script>
<script src="index.js"></script>
</head>
<body>
<h1>Login</h1>