working on login form
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -17,7 +17,7 @@ public class Backend extends PathHandler {
|
|||||||
System.out.printf("%s %s…", method, path);
|
System.out.printf("%s %s…", method, path);
|
||||||
|
|
||||||
if ("login".equals(path)) {
|
if ("login".equals(path)) {
|
||||||
doLogin(ex);
|
doLogin(ex); // TODO: prevent brute force
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var token = getAuthToken(ex);
|
var token = getAuthToken(ex);
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
var api = "/api";
|
var api = "/api";
|
||||||
|
var web = "/web";
|
||||||
@@ -12,8 +12,26 @@ function checkUser(){
|
|||||||
.then(handleCheckUser)
|
.then(handleCheckUser)
|
||||||
.catch((err) => console.log(err));
|
.catch((err) => console.log(err));
|
||||||
}
|
}
|
||||||
function submitForm(formId){
|
|
||||||
var data = Object.fromEntries(new FormData(document.getElementById(formId)));
|
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",{
|
fetch(api+"/login",{
|
||||||
headers: {
|
headers: {
|
||||||
'login-username': data.user,
|
'login-username': data.user,
|
||||||
@@ -21,5 +39,5 @@ function submitForm(formId){
|
|||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
});
|
}).then(handleLogin);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<span>Login failed!</span>
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Login</h1>
|
<h1>Login</h1>
|
||||||
<form id="form">
|
<form id="login">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>User credentials</legend>
|
<legend>User credentials</legend>
|
||||||
<label>
|
<label>
|
||||||
@@ -17,8 +17,9 @@
|
|||||||
Password
|
Password
|
||||||
<input type="password" name="pass" />
|
<input type="password" name="pass" />
|
||||||
</label>
|
</label>
|
||||||
<button type="button" onClick="submitForm('form')">Login</button>
|
<button type="button" onClick="tryLogin()">Login</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
<div id="error"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user