working on user login
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
1
de.srsoftware.oidc.web/src/main/resources/en/config.js
Normal file
1
de.srsoftware.oidc.web/src/main/resources/en/config.js
Normal file
@@ -0,0 +1 @@
|
||||
var api = "/api";
|
||||
@@ -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>
|
||||
25
de.srsoftware.oidc.web/src/main/resources/en/lightoidc.js
Normal file
25
de.srsoftware.oidc.web/src/main/resources/en/lightoidc.js
Normal 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'
|
||||
}
|
||||
});
|
||||
}
|
||||
24
de.srsoftware.oidc.web/src/main/resources/en/login.html
Normal file
24
de.srsoftware.oidc.web/src/main/resources/en/login.html
Normal 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>
|
||||
Reference in New Issue
Block a user