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,14 +41,16 @@ if (!$user)
include 'header.php';
?>
<main class="auth" role="main">
<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>
<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>
<p class="auth__alert__error account__toast" role="alert">Upload fehlgeschlagen. Bitte eine gültige
Bilddatei auswählen.</p>
<?php endif; ?>
<!-- ═══ Profil-Sidebar ═══ -->
@ -85,7 +82,12 @@ include 'header.php';
<!-- 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>
<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">
@ -103,7 +105,10 @@ include 'header.php';
<!-- 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>
<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">
@ -112,7 +117,8 @@ include 'header.php';
Produkt hinzufügen
</a>
<?php endif; ?>
<a href="wunschliste.php" class="auth__submit account__action-link account__action-link--secondary">
<a href="wunschliste.php"
class="auth__submit account__action-link account__action-link--secondary">
Meine Wunschliste
</a>
</div>
@ -121,7 +127,12 @@ include 'header.php';
<!-- 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>
<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>
@ -134,6 +145,6 @@ include 'header.php';
</div>
</section>
</main>
</main>
<?php include 'footer.php'; ?>