// login.js document.getElementById('loginForm').addEventListener('submit', async (e) => { e.preventDefault(); const username = document.getElementById('username').value; const password = document.getElementById('password').value; const loginBtn = document.getElementById('loginBtn'); // UI Feedback loginBtn.classList.add('btn-disabled'); loginBtn.innerHTML = ' Авторизация...'; try { const response = await fetch('/api/v1/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }) }); const data = await response.json(); if (data.success) { // Сохраняем токен localStorage.setItem('admin_token', data.data.token); showStatus('Успешно! Вход в систему...', 'success'); setTimeout(() => { window.location.href = '/admin'; }, 800); } else { showStatus(data.error || 'Ошибка входа', 'error'); resetButton(loginBtn); } } catch (err) { showStatus('Ошибка сети или сервера', 'error'); resetButton(loginBtn); } }); function resetButton(btn) { btn.classList.remove('btn-disabled'); btn.innerHTML = ' Войти в панель'; } function showStatus(message, type) { const notification = document.getElementById('notification'); notification.className = 'notification'; if (type === 'error') { notification.classList.add('notification-error'); notification.innerHTML = `

Ошибка:

${message}
`; } else { notification.classList.add('notification-success'); notification.innerHTML = `

Успешно:

${message}
`; } notification.style.display = 'block'; notification.style.opacity = '1'; }