rollback index.html
This commit is contained in:
+31
-5
@@ -85,6 +85,11 @@
|
|||||||
color: #166534;
|
color: #166534;
|
||||||
border: 1px solid #86efac;
|
border: 1px solid #86efac;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#captcha-container {
|
||||||
|
margin: 16px 0;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -92,38 +97,59 @@
|
|||||||
<h1>Login</h1>
|
<h1>Login</h1>
|
||||||
<form id="login">
|
<form id="login">
|
||||||
<label for="username">Benutzername</label>
|
<label for="username">Benutzername</label>
|
||||||
<input id="username" name="username" required />
|
<input id="username" name="username" required/>
|
||||||
<label for="password">Passwort</label>
|
<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>
|
||||||
<button type="submit">Einloggen</button>
|
<button type="submit">Einloggen</button>
|
||||||
</form>
|
</form>
|
||||||
<div class="msg" id="msg"></div>
|
<div class="msg" id="msg"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="https://hcaptcha.com/1/api.js" async defer></script>
|
||||||
<script>
|
<script>
|
||||||
const form = document.getElementById('login');
|
const form = document.getElementById('login');
|
||||||
const msg = document.getElementById('msg');
|
const msg = document.getElementById('msg');
|
||||||
|
const captchaContainer = document.getElementById('captcha-container');
|
||||||
|
|
||||||
form.addEventListener('submit', async (e) => {
|
form.addEventListener('submit', async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
msg.style.display = 'none';
|
msg.style.display = 'none';
|
||||||
const username = document.getElementById('username').value;
|
const username = document.getElementById('username').value;
|
||||||
const password = document.getElementById('password').value;
|
const password = document.getElementById('password').value;
|
||||||
const body = { username, password };
|
const captcha = hcaptcha.getResponse();
|
||||||
|
const body = { username, password, captcha };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/login', {
|
const res = await fetch('/login', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify(body)
|
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';
|
msg.style.display = 'block';
|
||||||
if (res.ok && data.ok) {
|
if (res.ok && data.ok) {
|
||||||
msg.textContent = '✅ Erfolgreich eingeloggt!';
|
msg.textContent = '✅ Erfolgreich eingeloggt!';
|
||||||
msg.className = 'msg success';
|
msg.className = 'msg success';
|
||||||
|
hcaptcha.reset();
|
||||||
} else {
|
} else {
|
||||||
msg.textContent = '❌ ' + (data.error || 'Login fehlgeschlagen');
|
msg.textContent = '❌ ' + (data.error || 'Login fehlgeschlagen');
|
||||||
msg.className = 'msg error';
|
msg.className = 'msg error';
|
||||||
msg.style.display = 'block';
|
if (data.requiresCaptcha) {
|
||||||
|
captchaContainer.style.display = 'block';
|
||||||
|
hcaptcha.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
msg.textContent = '⚠️ Netzwerkfehler: ' + err.message;
|
msg.textContent = '⚠️ Netzwerkfehler: ' + err.message;
|
||||||
msg.className = 'msg error';
|
msg.className = 'msg error';
|
||||||
|
|||||||
Reference in New Issue
Block a user