rollback index.html
This commit is contained in:
+29
-3
@@ -85,6 +85,11 @@
|
||||
color: #166534;
|
||||
border: 1px solid #86efac;
|
||||
}
|
||||
|
||||
#captcha-container {
|
||||
margin: 16px 0;
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -95,35 +100,56 @@
|
||||
<input id="username" name="username" required/>
|
||||
<label for="password">Passwort</label>
|
||||
<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>
|
||||
</form>
|
||||
<div class="msg" id="msg"></div>
|
||||
</div>
|
||||
<script src="https://hcaptcha.com/1/api.js" async defer></script>
|
||||
<script>
|
||||
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';
|
||||
const username = document.getElementById('username').value;
|
||||
const password = document.getElementById('password').value;
|
||||
const body = { username, password };
|
||||
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!';
|
||||
msg.className = 'msg success';
|
||||
hcaptcha.reset();
|
||||
} 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