From e341da417691bbfd3912f884738ae85a1ed34a06 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Sun, 7 Dec 2025 03:19:27 +0100 Subject: [PATCH] user --- public/account.php | 167 ++++++++++++++++++++++++++++++++++++ public/assets/js/account.js | 27 ++++++ public/assets/js/ui-user.js | 34 ++------ public/index.php | 137 +---------------------------- 4 files changed, 204 insertions(+), 161 deletions(-) create mode 100644 public/account.php create mode 100644 public/assets/js/account.js diff --git a/public/account.php b/public/account.php new file mode 100644 index 0000000..f17073d --- /dev/null +++ b/public/account.php @@ -0,0 +1,167 @@ + + + + + + + Email Template System – Konto + + + + + + + + +
+
+ ← Übersicht +

Mein Konto

+
+ U + +
+
+
+ +
+
+ + + + +
+ +
+

Profil

+
+ + +
+ +
+
+
+ + + + + + +
+ +
+ + + + + diff --git a/public/assets/js/account.js b/public/assets/js/account.js new file mode 100644 index 0000000..9d108ab --- /dev/null +++ b/public/assets/js/account.js @@ -0,0 +1,27 @@ +import { apiAction } from './api.js'; +import { initUserPanel, initAccountPage } from './ui-user.js'; +import { mountLogoutButton, ensureFloatingLogout } from './ui-auth.js'; + +async function ensureAuthenticated() { + try { + const me = await apiAction('auth.me', { method: 'GET' }); + if (!me?.ok || !me?.user) { + window.location.href = '/login.php'; + return false; + } + window.__currentUser = me.user; + document.documentElement.classList.remove('auth-pending'); + return true; + } catch { + return false; + } +} + +document.addEventListener('DOMContentLoaded', async () => { + const ok = await ensureAuthenticated(); + if (!ok) return; + initUserPanel(); + initAccountPage(); + mountLogoutButton('#btn-logout', { redirect: '/login.php' }); + ensureFloatingLogout({ redirect: '/login.php' }); +}); diff --git a/public/assets/js/ui-user.js b/public/assets/js/ui-user.js index 0be17fc..4dac3ab 100644 --- a/public/assets/js/ui-user.js +++ b/public/assets/js/ui-user.js @@ -9,7 +9,6 @@ const state = { loading: false, }; -let dialog; let avatarBtn; let profileForm; let passwordForm; @@ -18,31 +17,26 @@ let teamTable; let userForm; export function initUserPanel() { - dialog = document.getElementById('userDialog'); avatarBtn = document.getElementById('btn-user'); - if (!dialog || !avatarBtn) return; + updateAvatar(); +} +export function initAccountPage() { profileForm = document.getElementById('profileForm'); passwordForm = document.getElementById('passwordForm'); settingsForm = document.getElementById('settingsForm'); teamTable = document.getElementById('teamTable'); userForm = document.getElementById('userForm'); - avatarBtn.addEventListener('click', () => openUserDialog()); - document.getElementById('userClose')?.addEventListener('click', () => dialog.close()); - - profileForm?.addEventListener('submit', submitProfileForm); - passwordForm?.addEventListener('submit', submitPasswordForm); - settingsForm?.addEventListener('submit', submitSettingsForm); - document.getElementById('btn-user-add')?.addEventListener('click', () => openUserForm()); document.getElementById('userFormCancel')?.addEventListener('click', () => closeUserForm()); userForm?.addEventListener('submit', submitUserForm); + profileForm?.addEventListener('submit', submitProfileForm); + passwordForm?.addEventListener('submit', submitPasswordForm); + settingsForm?.addEventListener('submit', submitSettingsForm); teamTable?.addEventListener('click', handleTeamTableClick); - dialog.addEventListener('close', () => closeUserForm()); - document.querySelectorAll('[data-user-tab]').forEach(btn => { btn.addEventListener('click', () => switchTab(btn.getAttribute('data-user-tab'))); }); @@ -64,8 +58,8 @@ export function initUserPanel() { }); }); - updateAvatar(); - updateOwnerVisibility(); + switchTab(state.currentTab); + loadAccountData(); } function isOwner() { @@ -98,13 +92,6 @@ function switchTab(tab) { }); } -async function openUserDialog() { - if (dialog.open || state.loading) return; - dialog.showModal(); - switchTab(state.currentTab); - await loadAccountData(); -} - async function loadAccountData() { try { state.loading = true; @@ -123,7 +110,6 @@ async function loadAccountData() { } catch (err) { console.error(err); toast(err.message || 'Fehler beim Laden', false); - dialog.close(); } finally { state.loading = false; } @@ -343,10 +329,6 @@ function copyToClipboard(value) { } } -function closeUserDialog() { - dialog?.close(); -} - function escapeHtml(str) { return String(str || '') .replace(/&/g, '&') diff --git a/public/index.php b/public/index.php index 96446a5..0f36723 100644 --- a/public/index.php +++ b/public/index.php @@ -40,11 +40,6 @@ $assetVersion = defined('ASSET_VERSION') ? ASSET_VERSION : time(); .section-card{background:#fff;border:1px solid #e2e8f0;border-radius:1rem;padding:1rem;margin-bottom:1.25rem} .section-card h4{margin:0 0 .75rem;font-size:1rem;font-weight:600;color:#0f172a} .input{width:100%;border:1px solid #cbd5f5;border-radius:.5rem;padding:.5rem .75rem} - .user-tabs{display:flex;gap:.5rem;margin-bottom:1rem} - .user-panel{width:90vw;max-width:960px} - .team-table{width:100%;border-collapse:collapse;font-size:.9rem} - .team-table th,.team-table td{padding:.35rem .5rem;border-bottom:1px solid #e2e8f0;text-align:left} - .badge{display:inline-flex;align-items:center;padding:.1rem .5rem;border-radius:999px;font-size:.75rem;background:#e2e8f0;color:#0f172a} @@ -59,9 +54,9 @@ $assetVersion = defined('ASSET_VERSION') ? ASSET_VERSION : time();
- +
@@ -165,137 +160,9 @@ $assetVersion = defined('ASSET_VERSION') ? ASSET_VERSION : time(); - - -
-
- Mein Konto - -
-
-
- - - - -
- -
-

Profil

-
- - -
- -
-
-
- - - - - - -
-
-
-
-