Files
xxx-sphere-web/bin/main/static/login.html

108 lines
4.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/img/icon.png" type="image/png">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login xXx Sphere</title>
<link rel="stylesheet" href="/css/variables.css">
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<div class="card">
<img src="/img/icon.png" alt="Logo">
<h1>Bitte melde dich an</h1>
<label for="email">E-Mail</label>
<input type="email" id="email" placeholder="deine@email.de" autocomplete="username" />
<label for="password">Passwort</label>
<input type="password" id="password" placeholder="••••••••" autocomplete="current-password" />
<button class="full-width" id="loginBtn" onclick="login()">Anmelden</button>
<div class="message" id="message"></div>
<p style="text-align:center; margin-top:1.25rem; font-size:0.85rem;">
<a href="/forgot-password.html" style="color:var(--color-primary);">Passwort vergessen?</a>
</p>
<p style="text-align:center; margin-top:0.5rem; font-size:0.85rem;">
Noch kein Konto? <a href="/registration.html" style="color:var(--color-primary);">Registrieren</a>
</p>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const params = new URLSearchParams(window.location.search);
const email = params.get('email');
if (email) {
document.getElementById('email').value = email;
document.getElementById('password').focus();
showMessage('E-Mail-Adresse bestätigt! Du kannst dich jetzt anmelden.', 'success');
} else if (params.get('emailChanged')) {
showMessage('E-Mail-Adresse erfolgreich geändert. Bitte melde dich mit deiner neuen Adresse an.', 'success');
} else if (params.get('accountDeleted')) {
showMessage('Dein Konto wurde gelöscht.', 'success');
}
});
document.addEventListener('keydown', e => {
if (e.key === 'Enter') login();
});
async function login() {
const email = document.getElementById('email').value.trim();
const password = document.getElementById('password').value;
const btn = document.getElementById('loginBtn');
if (!email || !password) {
showMessage('Bitte E-Mail und Passwort eingeben.', 'error');
return;
}
btn.disabled = true;
btn.textContent = 'Wird geprüft…';
hideMessage();
try {
const response = await fetch('/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password })
});
if (response.status === 200) {
const user = await response.json();
sessionStorage.setItem('user', JSON.stringify(user));
window.location.href = '/userhome.html';
} else if (response.status === 204) {
showMessage('E-Mail oder Passwort falsch.', 'error');
btn.disabled = false;
btn.textContent = 'Anmelden';
} else {
showMessage(`Fehler: HTTP ${response.status}`, 'error');
btn.disabled = false;
btn.textContent = 'Anmelden';
}
} catch (err) {
showMessage('Server nicht erreichbar.', 'error');
btn.disabled = false;
btn.textContent = 'Anmelden';
console.error(err);
}
}
function showMessage(text, type) {
const el = document.getElementById('message');
el.textContent = text;
el.className = `message ${type}`;
el.style.display = 'block';
}
function hideMessage() {
document.getElementById('message').style.display = 'none';
}
</script>
</body>
</html>