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');
@ -50,10 +45,12 @@ include 'header.php';
<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
aktualisiert.</p>
<?php endif; ?> <?php endif; ?>
<?php if (isset($_GET['upload']) && $_GET['upload'] === 'err'): ?> <?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; ?> <?php endif; ?>
<!-- ═══ Profil-Sidebar ═══ --> <!-- ═══ Profil-Sidebar ═══ -->
@ -85,7 +82,12 @@ include 'header.php';
<!-- Profilbild ändern --> <!-- Profilbild ändern -->
<div class="auth__card account__section"> <div class="auth__card account__section">
<h2 class="account__section-title"> <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 Profilbild ändern
</h2> </h2>
<form class="auth__form" action="upload.php" method="post" enctype="multipart/form-data"> <form class="auth__form" action="upload.php" method="post" enctype="multipart/form-data">
@ -103,7 +105,10 @@ include 'header.php';
<!-- Schnellaktionen --> <!-- Schnellaktionen -->
<div class="auth__card account__section"> <div class="auth__card account__section">
<h2 class="account__section-title"> <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 Schnellaktionen
</h2> </h2>
<div class="account__quick-actions"> <div class="account__quick-actions">
@ -112,7 +117,8 @@ include 'header.php';
Produkt hinzufügen Produkt hinzufügen
</a> </a>
<?php endif; ?> <?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 Meine Wunschliste
</a> </a>
</div> </div>
@ -121,7 +127,12 @@ include 'header.php';
<!-- 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"
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 Sitzung beenden
</h2> </h2>
<p class="account__danger-text">Du wirst ausgeloggt und musst dich erneut anmelden.</p> <p class="account__danger-text">Du wirst ausgeloggt und musst dich erneut anmelden.</p>