Stephan Richter
5 months ago
13 changed files with 124 additions and 77 deletions
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
plugins { |
||||
id 'java' |
||||
} |
||||
|
||||
group = 'de.srsoftware' |
||||
version = '1.0-SNAPSHOT' |
||||
|
||||
repositories { |
||||
mavenCentral() |
||||
} |
||||
|
||||
dependencies { |
||||
testImplementation platform('org.junit:junit-bom:5.10.0') |
||||
testImplementation 'org.junit.jupiter:junit-jupiter' |
||||
} |
||||
|
||||
test { |
||||
useJUnitPlatform() |
||||
} |
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
const UNAUTHORIZED = 401; |
||||
|
||||
function handleUser(response){ |
||||
console.log(response); |
||||
} |
||||
|
||||
fetch(api+"/user").then(handleUser); |
@ -1,43 +0,0 @@
@@ -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); |
||||
} |
Loading…
Reference in new issue