53 lines
2.0 KiB
HTML
53 lines
2.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Вход в админку</title>
|
|
<link rel="stylesheet" href="style.css">
|
|
<style>
|
|
.login-container {
|
|
max-width: 400px;
|
|
margin: 4rem auto;
|
|
background: white;
|
|
padding: 2rem;
|
|
border-radius: 1.5rem;
|
|
box-shadow: 0 8px 20px rgba(0,0,0,0.1);
|
|
}
|
|
.error { color: #b91c1c; margin-top: 1rem; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<h2>Авторизация администратора</h2>
|
|
<form id="loginForm">
|
|
<label>Логин: <input type="text" id="username" required></label>
|
|
<label>Пароль: <input type="password" id="password" required></label>
|
|
<button type="submit">Войти</button>
|
|
<div id="errorMsg" class="error"></div>
|
|
</form>
|
|
</div>
|
|
<script>
|
|
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
const username = document.getElementById('username').value;
|
|
const password = document.getElementById('password').value;
|
|
const errorDiv = document.getElementById('errorMsg');
|
|
try {
|
|
const res = await fetch('/api/auth', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ username, password })
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok && data.success) {
|
|
window.location.href = '/admin';
|
|
} else {
|
|
errorDiv.innerText = data.message || 'Ошибка входа';
|
|
}
|
|
} catch (err) {
|
|
errorDiv.innerText = 'Ошибка соединения';
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |