Files
web_auth/index.html

37 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() {
2026-01-19 08:57:58 +03:00
const response = await fetch('api/check_auth.php', { credentials: 'same-origin' });
2026-01-19 08:35:00 +03:00
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() {
2026-01-19 08:57:58 +03:00
await fetch('api/logout.php', {
method: 'POST',
credentials: 'same-origin'
});
2026-01-19 08:35:00 +03:00
window.location.href = 'login.html';
}
// Проверяем авторизацию
checkAuth();
</script>
</body>
</html>