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';
if (empty($_SESSION['user_id']))
{
if (empty($_SESSION['user_id'])) {
header('Location: login.php');
exit();
}
@ -23,20 +22,16 @@ $stmt->execute();
$result = $stmt->get_result();
if ($result)
{
if ($result) {
$user = mysqli_fetch_assoc($result);
}
else
{
} else {
$user = null;
}
$stmt->close();
$conn->close();
if (!$user)
{
if (!$user) {
session_unset();
session_destroy();
header('Location: login.php');
@ -46,94 +41,110 @@ if (!$user)
include 'header.php';
?>
<main class="auth" role="main">
<section class="account" aria-label="Account Bereich">
<main class="auth" role="main">
<section class="account" aria-label="Account Bereich">
<?php if (isset($_GET['upload']) && $_GET['upload'] === 'ok'): ?>
<p class="auth__alert__sucess account__toast" role="status">Profilbild wurde erfolgreich aktualisiert.</p>
<?php endif; ?>
<?php if (isset($_GET['upload']) && $_GET['upload'] === 'err'): ?>
<p class="auth__alert__error account__toast" role="alert">Upload fehlgeschlagen. Bitte eine gültige Bilddatei auswählen.</p>
<?php endif; ?>
<?php if (isset($_GET['upload']) && $_GET['upload'] === 'ok'): ?>
<p class="auth__alert__sucess account__toast" role="status">Profilbild wurde erfolgreich
aktualisiert.</p>
<?php endif; ?>
<?php if (isset($_GET['upload']) && $_GET['upload'] === 'err'): ?>
<p class="auth__alert__error account__toast" role="alert">Upload fehlgeschlagen. Bitte eine gültige
Bilddatei auswählen.</p>
<?php endif; ?>
<!-- ═══ Profil-Sidebar ═══ -->
<div class="auth__card account__profile">
<div class="account__avatar-wrapper">
<img class="account__avatar"
src="<?php echo htmlspecialchars($user['profilePicture']); ?>"
alt="Profilbild von <?php echo htmlspecialchars($user['displayName'], ENT_QUOTES, 'UTF-8'); ?>"
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>
<!-- ═══ Profil-Sidebar ═══ -->
<div class="auth__card account__profile">
<div class="account__avatar-wrapper">
<img class="account__avatar"
src="<?php echo htmlspecialchars($user['profilePicture']); ?>"
alt="Profilbild von <?php echo htmlspecialchars($user['displayName'], ENT_QUOTES, 'UTF-8'); ?>"
width="180">
</div>
<div class="account__detail-row">
<dt>E-Mail</dt>
<dd><?php echo htmlspecialchars($user['email']); ?></dd>
<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 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>
</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>
<!-- 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 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>
<!-- Abmelden -->
<div class="auth__card account__section account__section--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>
Sitzung beenden
</h2>
<p class="account__danger-text">Du wirst ausgeloggt und musst dich erneut anmelden.</p>
<form action="logout.php" method="post">
<div class="auth__actions">
<button class="auth__submit auth__submit--danger" type="submit">Abmelden</button>
</div>
</form>
</div>
<!-- Abmelden -->
<div class="auth__card account__section account__section--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>
Sitzung beenden
</h2>
<p class="account__danger-text">Du wirst ausgeloggt und musst dich erneut anmelden.</p>
<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>
</section>
</main>
</div>
</section>
</main>
<?php include 'footer.php'; ?>