36 lines
1.1 KiB
HTML
36 lines
1.1 KiB
HTML
<!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> |