From 3f27a23ae01ee4fc50034998c79b911357d4124b Mon Sep 17 00:00:00 2001 From: Maaxxs <61059039+MaaxxsDev@users.noreply.github.com> Date: Fri, 18 Sep 2026 17:57:04 +0200 Subject: [PATCH] Embed the password-change form directly on the profile page Mein Profil previously just linked out to change_password.php. Now it has its own inline form (same validation as change_password.php), so changing your password no longer requires leaving the page. change_password.php still handles the forced first-login flow. Co-Authored-By: Claude Sonnet 5 --- profile.php | 62 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/profile.php b/profile.php index 0c61d59..43325f4 100644 --- a/profile.php +++ b/profile.php @@ -3,20 +3,38 @@ require_once __DIR__ . '/includes/bootstrap.php'; require_login(); $user = current_user(); -$error = null; +$profileError = null; +$passwordError = null; if ($_SERVER['REQUEST_METHOD'] === 'POST') { verify_csrf(); + $action = (string) ($_POST['action'] ?? ''); - $displayName = trim((string) ($_POST['display_name'] ?? '')); - if ($displayName === '') { - $error = 'Anzeigename darf nicht leer sein.'; - } else { - db()->prepare('UPDATE users SET display_name = ? WHERE id = ?')->execute([$displayName, $user['id']]); - set_flash('success', 'Profil wurde aktualisiert.'); - redirect('/profile.php'); + if ($action === 'update_profile') { + $displayName = trim((string) ($_POST['display_name'] ?? '')); + if ($displayName === '') { + $profileError = 'Anzeigename darf nicht leer sein.'; + } else { + db()->prepare('UPDATE users SET display_name = ? WHERE id = ?')->execute([$displayName, $user['id']]); + set_flash('success', 'Profil wurde aktualisiert.'); + redirect('/profile.php'); + } + $user['display_name'] = $displayName; + } elseif ($action === 'change_password') { + $newPassword = (string) ($_POST['new_password'] ?? ''); + $newPasswordConfirm = (string) ($_POST['new_password_confirm'] ?? ''); + + if (strlen($newPassword) < 8) { + $passwordError = 'Das neue Passwort muss mindestens 8 Zeichen lang sein.'; + } elseif ($newPassword !== $newPasswordConfirm) { + $passwordError = 'Die Passwörter stimmen nicht überein.'; + } else { + db()->prepare('UPDATE users SET password_hash = ?, must_change_password = 0 WHERE id = ?') + ->execute([password_hash($newPassword, PASSWORD_DEFAULT), $user['id']]); + set_flash('success', 'Passwort wurde geändert.'); + redirect('/profile.php'); + } } - $user['display_name'] = $displayName; } $pageTitle = 'Mein Profil'; @@ -29,11 +47,12 @@ include __DIR__ . '/includes/header.php';

Anzeigename

- -
+ +
+
@@ -43,9 +62,24 @@ include __DIR__ . '/includes/header.php';
-

Passwort

-

Du kannst dein Passwort jederzeit ändern.

- Passwort ändern +

Passwort ändern

+ +
+ + + + +
+ + +
Mindestens 8 Zeichen.
+
+
+ + +
+ +