92 lines
2.5 KiB
JavaScript
92 lines
2.5 KiB
JavaScript
function showMessage(elementId, message, isError = false) {
|
|
const messageDiv = document.getElementById(elementId);
|
|
messageDiv.textContent = message;
|
|
messageDiv.classList.add("show");
|
|
setTimeout(() => {
|
|
messageDiv.classList.remove("show");
|
|
}, 4000);
|
|
}
|
|
|
|
function showError(message) {
|
|
showMessage("error", message, true);
|
|
}
|
|
|
|
function showSuccess(message) {
|
|
showMessage("success", message, false);
|
|
}
|
|
|
|
function setLoading(isLoading) {
|
|
const btnText = document.getElementById("btn-text");
|
|
const btn = document.getElementById("loginBtn");
|
|
|
|
if (isLoading) {
|
|
btnText.innerHTML = '<span class="loading"></span>Anmelde...';
|
|
btn.disabled = true;
|
|
} else {
|
|
btnText.textContent = 'Anmelden';
|
|
btn.disabled = false;
|
|
}
|
|
}
|
|
|
|
async function handleLogin(event) {
|
|
event.preventDefault();
|
|
|
|
const username = document.getElementById('username').value.trim();
|
|
const password = document.getElementById('password').value;
|
|
|
|
if (!username || !password) {
|
|
showError('Bitte füllen Sie alle Felder aus.');
|
|
return;
|
|
}
|
|
|
|
setLoading(true);
|
|
|
|
try {
|
|
const response = await fetch('/api/v1/public/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ username, password })
|
|
});
|
|
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
showSuccess('✅ Anmeldung erfolgreich! Weiterleitung...');
|
|
setTimeout(() => {
|
|
window.location.href = '/admin-dashboard';
|
|
}, 1000);
|
|
} else {
|
|
showError(result.message || 'Anmeldung fehlgeschlagen');
|
|
}
|
|
} catch (error) {
|
|
console.error('Fehler bei der Anmeldung:', error);
|
|
showError('Verbindungsfehler. Bitte versuchen Sie es erneut.');
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}
|
|
|
|
// Enter-Taste für Login
|
|
document.addEventListener('keypress', function(e) {
|
|
if (e.key === 'Enter') {
|
|
handleLogin(e);
|
|
}
|
|
});
|
|
|
|
// Fokus auf erstes Eingabefeld
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
document.getElementById('username').focus();
|
|
|
|
// Add cookie settings button functionality
|
|
const cookieSettingsBtn = document.getElementById('cookie-settings-footer');
|
|
if (cookieSettingsBtn) {
|
|
cookieSettingsBtn.addEventListener('click', function() {
|
|
if (window.cookieConsent) {
|
|
window.cookieConsent.resetConsent();
|
|
}
|
|
});
|
|
}
|
|
});
|