This commit is contained in:
2025-12-08 00:07:43 +01:00
parent 352ad4c512
commit b3f10164de
2 changed files with 10 additions and 12 deletions

View File

@@ -2,8 +2,6 @@ import { apiAction } from './api.js';
import { initUserPanel, initAccountPage } from './ui-user.js'; import { initUserPanel, initAccountPage } from './ui-user.js';
import { mountLogoutButton, ensureFloatingLogout } from './ui-auth.js'; import { mountLogoutButton, ensureFloatingLogout } from './ui-auth.js';
const pageType = document.body?.dataset?.page || 'account';
async function ensureAuthenticated() { async function ensureAuthenticated() {
try { try {
const me = await apiAction('auth.me', { method: 'GET' }); const me = await apiAction('auth.me', { method: 'GET' });
@@ -19,19 +17,9 @@ async function ensureAuthenticated() {
} }
} }
function ensureAccess() {
const role = (window.__currentUser?.role || '').toLowerCase();
if (pageType === 'admin' && role !== 'owner' && role !== 'admin') {
window.location.href = '/account.php';
return false;
}
return true;
}
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
const ok = await ensureAuthenticated(); const ok = await ensureAuthenticated();
if (!ok) return; if (!ok) return;
if (!ensureAccess()) return;
initUserPanel(); initUserPanel();
initAccountPage(); initAccountPage();
mountLogoutButton('#btn-logout', { redirect: '/login.php' }); mountLogoutButton('#btn-logout', { redirect: '/login.php' });

View File

@@ -12,6 +12,8 @@ const state = {
loading: false, loading: false,
}; };
const pageType = document.body?.dataset?.page || 'account';
let avatarBtn; let avatarBtn;
let userMenuPanel; let userMenuPanel;
let profileForm; let profileForm;
@@ -103,6 +105,13 @@ function isAdmin() {
return role === 'owner' || role === 'admin'; return role === 'owner' || role === 'admin';
} }
function enforcePageAccess() {
if (pageType !== 'admin') return;
if (isAdmin()) return;
toast('Kein Zugriff auf diesen Bereich', false, { duration: 2500 });
window.location.href = '/account.php';
}
function updateAvatar() { function updateAvatar() {
const target = document.getElementById('userAvatar'); const target = document.getElementById('userAvatar');
if (!target) return; if (!target) return;
@@ -184,6 +193,7 @@ async function loadAccountData() {
window.__currentUser = res.user; window.__currentUser = res.user;
updateAvatar(); updateAvatar();
updateRoleVisibility(); updateRoleVisibility();
enforcePageAccess();
} }
fillProfileForm(res.user); fillProfileForm(res.user);
fillSettingsForm(res.settings || {}); fillSettingsForm(res.settings || {});