Files
web_auth/index.html

36 lines
1.1 KiB
HTML
Raw Normal View History

2026-01-19 08:35:00 +03:00
<!DOCTYPE html>
<html>
<head>
<title>Личный кабинет</title>
</head>
<body>
<div id="user-info"></div>
<button onclick="logout()">Выйти</button>
<script>
// Проверка авторизации при загрузке страницы
async function checkAuth() {
const response = await fetch('api/check_auth.php');
const result = await response.json();
if (!result.isLoggedIn) {
window.location.href = 'login.html';
} else {
document.getElementById('user-info').innerHTML = `
<h2>Добро пожаловать, ${result.user.username}!</h2>
`;
}
}
async function logout() {
await fetch('api/logout.php');
localStorage.removeItem('user');
localStorage.removeItem('isLoggedIn');
window.location.href = 'login.html';
}
// Проверяем авторизацию
checkAuth();
</script>
</body>
</html>