Refactor account.php for improved readability and consistency in code structure

This commit is contained in:
Fabian Schieder 2026-03-30 19:02:37 +02:00
parent 27a64f2b02
commit e110b86de2

View File

@ -2,8 +2,7 @@
require_once __DIR__ . '/lib/bootstrap.php'; require_once __DIR__ . '/lib/bootstrap.php';
if (empty($_SESSION['user_id'])) if (empty($_SESSION['user_id'])) {
{
header('Location: login.php'); header('Location: login.php');
exit(); exit();
} }
@ -23,20 +22,16 @@ $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
if ($result) if ($result) {
{
$user = mysqli_fetch_assoc($result); $user = mysqli_fetch_assoc($result);
} } else {
else
{
$user = null; $user = null;
} }
$stmt->close(); $stmt->close();
$conn->close(); $conn->close();
if (!$user) if (!$user) {
{
session_unset(); session_unset();
session_destroy(); session_destroy();
header('Location: login.php'); header('Location: login.php');
@ -46,94 +41,110 @@ if (!$user)
include 'header.php'; include 'header.php';
?> ?>
<main class="auth" role="main"> <main class="auth" role="main">
<section class="account" aria-label="Account Bereich"> <section class="account" aria-label="Account Bereich">
<?php if (isset($_GET['upload']) && $_GET['upload'] === 'ok'): ?> <?php if (isset($_GET['upload']) && $_GET['upload'] === 'ok'): ?>
<p class="auth__alert__sucess account__toast" role="status">Profilbild wurde erfolgreich aktualisiert.</p> <p class="auth__alert__sucess account__toast" role="status">Profilbild wurde erfolgreich
<?php endif; ?> aktualisiert.</p>
<?php if (isset($_GET['upload']) && $_GET['upload'] === 'err'): ?> <?php endif; ?>
<p class="auth__alert__error account__toast" role="alert">Upload fehlgeschlagen. Bitte eine gültige Bilddatei auswählen.</p> <?php if (isset($_GET['upload']) && $_GET['upload'] === 'err'): ?>
<?php endif; ?> <p class="auth__alert__error account__toast" role="alert">Upload fehlgeschlagen. Bitte eine gültige
Bilddatei auswählen.</p>
<?php endif; ?>
<!-- ═══ Profil-Sidebar ═══ --> <!-- ═══ Profil-Sidebar ═══ -->
<div class="auth__card account__profile"> <div class="auth__card account__profile">
<div class="account__avatar-wrapper"> <div class="account__avatar-wrapper">
<img class="account__avatar" <img class="account__avatar"
src="<?php echo htmlspecialchars($user['profilePicture']); ?>" src="<?php echo htmlspecialchars($user['profilePicture']); ?>"
alt="Profilbild von <?php echo htmlspecialchars($user['displayName'], ENT_QUOTES, 'UTF-8'); ?>" alt="Profilbild von <?php echo htmlspecialchars($user['displayName'], ENT_QUOTES, 'UTF-8'); ?>"
width="180"> width="180">
</div>
<h1 class="account__displayname"><?php echo htmlspecialchars($user['displayName'], ENT_QUOTES, 'UTF-8'); ?></h1>
<dl class="account__details">
<div class="account__detail-row">
<dt>User-ID</dt>
<dd>#<?php echo (int)$user['userID']; ?></dd>
</div> </div>
<div class="account__detail-row">
<dt>E-Mail</dt> <h1 class="account__displayname"><?php echo htmlspecialchars($user['displayName'], ENT_QUOTES, 'UTF-8'); ?></h1>
<dd><?php echo htmlspecialchars($user['email']); ?></dd>
<dl class="account__details">
<div class="account__detail-row">
<dt>User-ID</dt>
<dd>#<?php echo (int)$user['userID']; ?></dd>
</div>
<div class="account__detail-row">
<dt>E-Mail</dt>
<dd><?php echo htmlspecialchars($user['email']); ?></dd>
</div>
</dl>
</div>
<!-- ═══ Einstellungen ═══ -->
<div class="account__settings">
<!-- Profilbild ändern -->
<div class="auth__card account__section">
<h2 class="account__section-title">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>
<circle cx="8.5" cy="8.5" r="1.5"/>
<polyline points="21 15 16 10 5 21"/>
</svg>
Profilbild ändern
</h2>
<form class="auth__form" action="upload.php" method="post" enctype="multipart/form-data">
<div class="auth__field">
<label for="file">Neue Bilddatei auswählen</label>
<input type="file" name="uploadFile" id="file" accept="image/*" required>
<p class="auth__tip">Erlaubt: JPG / PNG &middot; max. 20 MB</p>
</div>
<div class="auth__actions">
<button class="auth__submit" type="submit">Hochladen</button>
</div>
</form>
</div> </div>
</dl>
</div>
<!-- ═══ Einstellungen ═══ --> <!-- Schnellaktionen -->
<div class="account__settings"> <div class="auth__card account__section">
<h2 class="account__section-title">
<!-- Profilbild ändern --> <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor"
<div class="auth__card account__section"> stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<h2 class="account__section-title"> <path d="M12 5v14M5 12h14"/>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg> </svg>
Profilbild ändern Schnellaktionen
</h2> </h2>
<form class="auth__form" action="upload.php" method="post" enctype="multipart/form-data"> <div class="account__quick-actions">
<div class="auth__field"> <?php if (!empty($_SESSION['user_roles']) && in_array('ADMIN', $_SESSION['user_roles'], true)): ?>
<label for="file">Neue Bilddatei auswählen</label> <a href="productAdder.php" class="auth__submit account__action-link">
<input type="file" name="uploadFile" id="file" accept="image/*" required> Produkt hinzufügen
<p class="auth__tip">Erlaubt: JPG / PNG &middot; max. 20 MB</p> </a>
<?php endif; ?>
<a href="wunschliste.php"
class="auth__submit account__action-link account__action-link--secondary">
Meine Wunschliste
</a>
</div> </div>
<div class="auth__actions">
<button class="auth__submit" type="submit">Hochladen</button>
</div>
</form>
</div>
<!-- Schnellaktionen -->
<div class="auth__card account__section">
<h2 class="account__section-title">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14M5 12h14"/></svg>
Schnellaktionen
</h2>
<div class="account__quick-actions">
<?php if (!empty($_SESSION['user_roles']) && in_array('ADMIN', $_SESSION['user_roles'], true)): ?>
<a href="productAdder.php" class="auth__submit account__action-link">
Produkt hinzufügen
</a>
<?php endif; ?>
<a href="wunschliste.php" class="auth__submit account__action-link account__action-link--secondary">
Meine Wunschliste
</a>
</div> </div>
</div>
<!-- Abmelden --> <!-- Abmelden -->
<div class="auth__card account__section account__section--danger"> <div class="auth__card account__section account__section--danger">
<h2 class="account__section-title account__section-title--danger"> <h2 class="account__section-title account__section-title--danger">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg> <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor"
Sitzung beenden stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
</h2> <path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/>
<p class="account__danger-text">Du wirst ausgeloggt und musst dich erneut anmelden.</p> <polyline points="16 17 21 12 16 7"/>
<form action="logout.php" method="post"> <line x1="21" y1="12" x2="9" y2="12"/>
<div class="auth__actions"> </svg>
<button class="auth__submit auth__submit--danger" type="submit">Abmelden</button> Sitzung beenden
</div> </h2>
</form> <p class="account__danger-text">Du wirst ausgeloggt und musst dich erneut anmelden.</p>
</div> <form action="logout.php" method="post">
<div class="auth__actions">
<button class="auth__submit auth__submit--danger" type="submit">Abmelden</button>
</div>
</form>
</div>
</div> </div>
</section> </section>
</main> </main>
<?php include 'footer.php'; ?> <?php include 'footer.php'; ?>