next front end
This commit is contained in:
@@ -99,8 +99,8 @@
|
||||
<i class="bi bi-person-circle"></i> User
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" href="/admin" data-shortcut="Alt+A"><i class="bi bi-gear"></i> Admin <small>(Alt+A)</small></a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li id="admin-menu-item" style="display: none;"><a class="dropdown-item" href="/admin" data-shortcut="Alt+A"><i class="bi bi-gear"></i> Admin <small>(Alt+A)</small></a></li>
|
||||
<li id="admin-menu-divider" style="display: none;"><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item" href="#" onclick="logout()"><i class="bi bi-box-arrow-right"></i> Logout</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
@@ -122,7 +122,7 @@
|
||||
<div class="row align-items-center">
|
||||
<div class="col-md-6">
|
||||
<small class="text-muted">
|
||||
© 2024 Delphi Consulting Group Database System
|
||||
© <span id="currentYear"></span> Delphi Consulting Group Database System
|
||||
<span class="mx-2">|</span>
|
||||
<span id="currentPageDisplay">Loading...</span>
|
||||
</small>
|
||||
@@ -218,7 +218,9 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
initializeKeyboardShortcuts();
|
||||
updateCurrentPageDisplay();
|
||||
updateCurrentYear();
|
||||
initializeAuthManager();
|
||||
checkUserPermissions();
|
||||
});
|
||||
|
||||
// Update current page display in footer
|
||||
@@ -243,6 +245,48 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Update current year in footer
|
||||
function updateCurrentYear() {
|
||||
const currentYear = new Date().getFullYear();
|
||||
const yearElement = document.getElementById('currentYear');
|
||||
if (yearElement) {
|
||||
yearElement.textContent = currentYear;
|
||||
}
|
||||
}
|
||||
|
||||
// Check user permissions and show/hide admin menu
|
||||
async function checkUserPermissions() {
|
||||
const token = localStorage.getItem('auth_token');
|
||||
if (!token || isLoginPage()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/auth/me', {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const user = await response.json();
|
||||
if (user.is_admin) {
|
||||
// Show admin menu items
|
||||
document.getElementById('admin-menu-item').style.display = 'block';
|
||||
document.getElementById('admin-menu-divider').style.display = 'block';
|
||||
}
|
||||
|
||||
// Update user display name if available
|
||||
const userDropdown = document.querySelector('.nav-link.dropdown-toggle');
|
||||
if (user.full_name && userDropdown) {
|
||||
userDropdown.innerHTML = `<i class="bi bi-person-circle"></i> ${user.full_name}`;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking user permissions:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Authentication Manager
|
||||
function initializeAuthManager() {
|
||||
// Check if we have a valid token on page load
|
||||
|
||||
Reference in New Issue
Block a user