init
This commit is contained in:
36
index.html
Normal file
36
index.html
Normal file
@@ -0,0 +1,36 @@
|
||||
<!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>
|
||||
Reference in New Issue
Block a user