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);
|
||||
|
||||
if ("login".equals(path)) {
|
||||
doLogin(ex);
|
||||
doLogin(ex); // TODO: prevent brute force
|
||||
return;
|
||||
}
|
||||
var token = getAuthToken(ex);
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
var api = "/api";
|
||||
var api = "/api";
|
||||
var web = "/web";
|
||||
@@ -12,8 +12,26 @@ function checkUser(){
|
||||
.then(handleCheckUser)
|
||||
.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",{
|
||||
headers: {
|
||||
'login-username': data.user,
|
||||
@@ -21,5 +39,5 @@ function submitForm(formId){
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
}).then(handleLogin);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<span>Login failed!</span>
|
||||
@@ -6,7 +6,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Login</h1>
|
||||
<form id="form">
|
||||
<form id="login">
|
||||
<fieldset>
|
||||
<legend>User credentials</legend>
|
||||
<label>
|
||||
@@ -17,8 +17,9 @@
|
||||
Password
|
||||
<input type="password" name="pass" />
|
||||
</label>
|
||||
<button type="button" onClick="submitForm('form')">Login</button>
|
||||
<button type="button" onClick="tryLogin()">Login</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
<div id="error"></div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user