feat: добавить веб-интерфейс админ-панели для управления модпаками
This commit is contained in:
@@ -357,24 +357,63 @@
|
||||
const username = localStorage.getItem('username');
|
||||
const nav = document.getElementById('mainNav');
|
||||
if (token && username) {
|
||||
nav.innerHTML =
|
||||
'<a href="/" id="nav-home">Главная</a>' +
|
||||
'<a href="/profile" id="nav-profile">Профиль</a>' +
|
||||
'<div class="nav-user"><div class="avatar"></div>' + escapeHtml(username) + '</div>' +
|
||||
'<a href="#" id="nav-logout" class="btn btn-sm btn-danger" style="padding:0.35rem 0.75rem">Выйти</a>';
|
||||
document.getElementById('nav-logout').addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('uuid');
|
||||
localStorage.removeItem('username');
|
||||
window.location.href = '/';
|
||||
// Fetch user info to check role
|
||||
fetch('/api/web/me', {
|
||||
headers: {'Authorization': 'Bearer ' + token}
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) throw new Error('Not authenticated');
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
let adminLink = '';
|
||||
if (data.role === 'admin') {
|
||||
adminLink = '<a href="/admin" id="nav-admin" class="btn btn-sm" style="background:var(--warning);color:#000">Админ-панель</a>';
|
||||
}
|
||||
|
||||
nav.innerHTML =
|
||||
'<a href="/" id="nav-home">Главная</a>' +
|
||||
'<a href="/profile" id="nav-profile">Профиль</a>' +
|
||||
adminLink +
|
||||
'<div class="nav-user"><div class="avatar"></div>' + escapeHtml(username) + '</div>' +
|
||||
'<a href="#" id="nav-logout" class="btn btn-sm btn-danger" style="padding:0.35rem 0.75rem">Выйти</a>';
|
||||
|
||||
document.getElementById('nav-logout').addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('uuid');
|
||||
localStorage.removeItem('username');
|
||||
window.location.href = '/';
|
||||
});
|
||||
|
||||
// Highlight active nav link
|
||||
const path = window.location.pathname;
|
||||
document.querySelectorAll('header nav a').forEach(function(a) {
|
||||
if (a.getAttribute('href') === path) a.classList.add('active');
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
// If we can't fetch user info, still show basic nav
|
||||
nav.innerHTML =
|
||||
'<a href="/" id="nav-home">Главная</a>' +
|
||||
'<a href="/profile" id="nav-profile">Профиль</a>' +
|
||||
'<div class="nav-user"><div class="avatar"></div>' + escapeHtml(username) + '</div>' +
|
||||
'<a href="#" id="nav-logout" class="btn btn-sm btn-danger" style="padding:0.35rem 0.75rem">Выйти</a>';
|
||||
document.getElementById('nav-logout').addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('uuid');
|
||||
localStorage.removeItem('username');
|
||||
window.location.href = '/';
|
||||
});
|
||||
|
||||
// Highlight active nav link
|
||||
const path = window.location.pathname;
|
||||
document.querySelectorAll('header nav a').forEach(function(a) {
|
||||
if (a.getAttribute('href') === path) a.classList.add('active');
|
||||
});
|
||||
});
|
||||
}
|
||||
// Highlight active nav link
|
||||
const path = window.location.pathname;
|
||||
document.querySelectorAll('header nav a').forEach(function(a) {
|
||||
if (a.getAttribute('href') === path) a.classList.add('active');
|
||||
});
|
||||
})();
|
||||
function escapeHtml(s) {
|
||||
const d = document.createElement('div');
|
||||
|
||||
Reference in New Issue
Block a user