// Gestion du thème const body = document.body; const themeSwitcher = document.getElementById('authlogin-theme-switch'); function setTheme(theme) { if (theme === 'dark') { body.classList.add('dark'); } else { body.classList.remove('dark'); } localStorage.setItem('theme', theme); } // Initialisation du thème const savedTheme = localStorage.getItem('theme'); if (savedTheme) { setTheme(savedTheme); } else if (window.matchMedia('(prefers-color-scheme: dark)').matches) { setTheme('dark'); } themeSwitcher.addEventListener('click', () => { body.classList.contains('dark') ? setTheme('light') : setTheme('dark'); }); // Gestion du formulaire de connexion document.getElementById('authlogin-form').addEventListener('submit', function(e) { e.preventDefault(); const username = document.getElementById('authlogin-username').value; const password = document.getElementById('authlogin-password').value; const loginButton = document.getElementById('authlogin-submit'); // Animation de chargement loginButton.disabled = true; loginButton.innerHTML = `
Connexion en cours...
`; fetch('/auth/activedirectory', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }), redirect: 'follow', }) .then(response => { if (response.url.includes('/dpanel/dashboard')) { loginButton.classList.add('success-animation'); loginButton.innerHTML = 'Succès!'; // Crée l'effet de vague const ripple = document.createElement('span'); ripple.style.cssText = ` position: absolute; background: rgba(255, 255, 255, 0.3); border-radius: 50%; pointer-events: none; width: 200px; height: 200px; transform: translate(-50%, -50%) scale(0); animation: ripple 1s ease-out; `; loginButton.appendChild(ripple); setTimeout(() => { const formContainer = document.querySelector('.form-container'); const h1Title = document.querySelector('h1'); formContainer.style.opacity = '0'; formContainer.style.transform = 'translateY(-20px) scale(0.98)'; h1Title.style.transform = 'translateY(20px)'; h1Title.style.opacity = '0'; setTimeout(() => { formContainer.innerHTML = `

Connexion réussie !

Redirection vers le tableau de bord...

`; formContainer.style.opacity = '1'; formContainer.style.transform = 'translateY(0) scale(1)'; h1Title.textContent = 'Bienvenue !'; h1Title.style.transform = 'translateY(0)'; h1Title.style.opacity = '1'; setTimeout(() => window.location.replace('/dpanel/dashboard'), 1500); }, 300); }, 700); } else { throw new Error('Échec de la connexion'); } }) .catch(error => { loginButton.classList.add('fail-animation'); loginButton.innerHTML = 'Échec'; if ('vibrate' in navigator) { navigator.vibrate(100); } setTimeout(() => { loginButton.classList.remove('fail-animation'); loginButton.disabled = false; loginButton.innerHTML = 'Se connecter'; }, 1500); }); }); function redirectToDiscord(url) { const discordButton = document.getElementById('authlogin-discord'); if (discordButton) { discordButton.innerHTML = `
Redirection en cours...
`; discordButton.disabled = true; setTimeout(() => { document.querySelector('.form-container').style.opacity = '0'; document.querySelector('.form-container').style.transform = 'translateY(-20px) scale(0.98)'; setTimeout(() => window.location.href = url, 500); }, 500); } }