working on user login

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-07-17 00:18:14 +02:00
parent 5627db16b5
commit add4209a1f
22 changed files with 173 additions and 401 deletions

View File

@@ -0,0 +1 @@
var api = "/api";

View File

@@ -1,9 +1,13 @@
<html>
<head>
<title>{title}</title>
<script src="lightoidc.js" />
<title>Light OIDC</title>
<script src="config.js"></script>
<script src="lightoidc.js"></script>
<script>
checkUser();
</script>
</head>
<body>
{body}
<h1>Welcome!</h1>
</body>
</html>

View File

@@ -0,0 +1,25 @@
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 submitForm(formId){
var data = Object.fromEntries(new FormData(document.getElementById(formId)));
fetch(api+"/login",{
headers: {
'login-username': data.user,
'login-password': data.pass, // TODO: send via body?
Accept: 'application/json',
'Content-Type': 'application/json'
}
});
}

View File

@@ -0,0 +1,24 @@
<html>
<head>
<title>Light OIDC</title>
<script src="config.js"></script>
<script src="lightoidc.js"></script>
</head>
<body>
<h1>Login</h1>
<form id="form">
<fieldset>
<legend>User credentials</legend>
<label>
Username
<input type="text" name="user" />
</label>
<label>
Password
<input type="password" name="pass" />
</label>
<button type="button" onClick="submitForm('form')">Login</button>
</fieldset>
</form>
</body>
</html>