Small fix in frontend
This commit is contained in:
+17
-7
@@ -1,8 +1,8 @@
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>Login</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
@@ -22,7 +22,7 @@
|
||||
background: white;
|
||||
padding: 32px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 24px rgba(0,0,0,0.1);
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
|
||||
max-width: 400px;
|
||||
width: 100%;
|
||||
}
|
||||
@@ -97,9 +97,9 @@
|
||||
<h1>Login</h1>
|
||||
<form id="login">
|
||||
<label for="username">Benutzername</label>
|
||||
<input id="username" name="username" required />
|
||||
<input id="username" name="username" required/>
|
||||
<label for="password">Passwort</label>
|
||||
<input id="password" name="password" type="password" required />
|
||||
<input id="password" name="password" type="password" required/>
|
||||
<div id="captcha-container">
|
||||
<div class="h-captcha" data-sitekey="10000000-ffff-ffff-ffff-000000000001"></div>
|
||||
</div>
|
||||
@@ -112,6 +112,7 @@
|
||||
const form = document.getElementById('login');
|
||||
const msg = document.getElementById('msg');
|
||||
const captchaContainer = document.getElementById('captcha-container');
|
||||
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
msg.style.display = 'none';
|
||||
@@ -119,13 +120,22 @@
|
||||
const password = document.getElementById('password').value;
|
||||
const captcha = hcaptcha.getResponse();
|
||||
const body = { username, password, captcha };
|
||||
|
||||
try {
|
||||
const res = await fetch('/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
let data = {};
|
||||
try {
|
||||
data = await res.json(); // versuche JSON zu parsen
|
||||
} catch (e) {
|
||||
console.warn("Antwort war kein JSON:", e);
|
||||
data = { ok: false, error: res.statusText };
|
||||
}
|
||||
|
||||
msg.style.display = 'block';
|
||||
if (res.ok && data.ok) {
|
||||
msg.textContent = '✅ Erfolgreich eingeloggt!';
|
||||
@@ -134,12 +144,12 @@
|
||||
} else {
|
||||
msg.textContent = '❌ ' + (data.error || 'Login fehlgeschlagen');
|
||||
msg.className = 'msg error';
|
||||
msg.style.display = 'block';
|
||||
if (data.requiresCaptcha) {
|
||||
captchaContainer.style.display = 'block';
|
||||
hcaptcha.reset();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
msg.textContent = '⚠️ Netzwerkfehler: ' + err.message;
|
||||
msg.className = 'msg error';
|
||||
|
||||
Reference in New Issue
Block a user