4.7.1: Фикс открытия админ-панели
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m11s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m11s
This commit is contained in:
@@ -161,10 +161,52 @@
|
||||
color: white;
|
||||
}
|
||||
|
||||
.auth-error {
|
||||
background: white;
|
||||
padding: 30px;
|
||||
border-radius: 10px;
|
||||
text-align: center;
|
||||
max-width: 500px;
|
||||
margin: 50px auto;
|
||||
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.auth-error h2 {
|
||||
color: #f44336;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.auth-error p {
|
||||
color: #666;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.auth-error a {
|
||||
display: inline-block;
|
||||
padding: 10px 20px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.auth-error a:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div id="authErrorContainer" style="display: none;">
|
||||
<div class="auth-error">
|
||||
<h2>⚠️ Требуется авторизация</h2>
|
||||
<p id="authErrorMessage">Для доступа к админ-панели необходимо войти в систему как администратор.</p>
|
||||
<a href="/" target="_self">Перейти на главную страницу</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container" id="mainContainer">
|
||||
<h1>🎯 Play Life Backend - Admin Panel</h1>
|
||||
|
||||
<div class="grid">
|
||||
@@ -214,12 +256,63 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Получаем токен из localStorage
|
||||
function getAuthToken() {
|
||||
return localStorage.getItem('access_token');
|
||||
}
|
||||
|
||||
// Проверяем авторизацию при загрузке страницы
|
||||
function checkAuth() {
|
||||
const token = getAuthToken();
|
||||
if (!token) {
|
||||
showAuthError('Токен авторизации не найден. Пожалуйста, войдите в систему.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Показываем сообщение об ошибке авторизации
|
||||
function showAuthError(message) {
|
||||
document.getElementById('authErrorContainer').style.display = 'block';
|
||||
document.getElementById('mainContainer').style.display = 'none';
|
||||
document.getElementById('authErrorMessage').textContent = message;
|
||||
}
|
||||
|
||||
// Обрабатываем ошибки авторизации
|
||||
function handleAuthError(response) {
|
||||
if (response.status === 401) {
|
||||
showAuthError('Сессия истекла. Пожалуйста, войдите в систему снова.');
|
||||
return true;
|
||||
} else if (response.status === 403) {
|
||||
showAuthError('У вас нет прав доступа к админ-панели. Требуются права администратора.');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Получаем заголовки с авторизацией
|
||||
function getAuthHeaders() {
|
||||
const token = getAuthToken();
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
if (token) {
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
function getApiUrl() {
|
||||
// Автоматически определяем URL текущего хоста
|
||||
// Админка обслуживается тем же бекендом, поэтому используем текущий origin
|
||||
return window.location.origin;
|
||||
}
|
||||
|
||||
// Проверяем авторизацию при загрузке страницы
|
||||
if (!checkAuth()) {
|
||||
// Страница уже скрыта в checkAuth
|
||||
}
|
||||
|
||||
function showStatus(elementId, status, text) {
|
||||
const statusEl = document.getElementById(elementId);
|
||||
statusEl.textContent = text;
|
||||
@@ -267,9 +360,7 @@
|
||||
try {
|
||||
const response = await fetch(`${getApiUrl()}/message/post`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers: getAuthHeaders(),
|
||||
body: JSON.stringify({
|
||||
body: {
|
||||
text: text
|
||||
@@ -277,6 +368,10 @@
|
||||
})
|
||||
});
|
||||
|
||||
if (handleAuthError(response)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
@@ -299,11 +394,13 @@
|
||||
try {
|
||||
const response = await fetch(`${getApiUrl()}/weekly_goals/setup`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
|
||||
if (handleAuthError(response)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
@@ -326,11 +423,13 @@
|
||||
try {
|
||||
const response = await fetch(`${getApiUrl()}/daily-report/trigger`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
|
||||
if (handleAuthError(response)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user