diff --git a/Controller/UserController.php b/Controller/UserController.php
index 92aaadd..4d1cfdf 100644
--- a/Controller/UserController.php
+++ b/Controller/UserController.php
@@ -26,8 +26,8 @@ class UserController{
];
private $changeUserLabels = [
- 'name' => 'Vorname*',
- 'lastname' => 'Nachname*',
+ 'vorname' => 'Vorname*',
+ 'name' => 'Nachname*',
'email' => 'E-Mail*',
'password' => 'Passwort*',
];
@@ -210,19 +210,19 @@ class UserController{
}
$validData = [
+ 'vorname' => $currentUser["vorname"],
'name' => $currentUser["name"],
- 'vorname' => $currentUser["vorname"],
'email' => $currentUser["email"],
];
$this->view->setVars([
- 'labels' => $this->changeUserLabels,
- 'validData' => $validData,
- 'errors' => $this->errors,
- 'message' => $this->message ?? null,
+ 'changeUserLabels' => $this->changeUserLabels,
+ 'validData' => $validData,
+ 'errors' => $this->errors,
]);
- $this->view->render('User/showUserChangeAccountSettings');
+ //$this->view->render('User/showUserChangeAccountSettings');
+ return;
}
public function updateAccountData()
@@ -259,46 +259,59 @@ class UserController{
$this->errors['password'] = 'Passwort muss mindestens 6 Zeichen haben.';
}
+
if (count($this->errors) > 0) {
$this->view->setVars([
'labels' => $this->changeUserLabels,
'validData' => $submitted,
'errors' => $this->errors,
]);
- return $this->showUserChangeAccountSettings();
+ return;
+ $this->view->render('User/showUserChangeAccountSettings');
}
$updateData = [];
- foreach (['name','lastname','email'] as $field) {
- if ($submitted[$field] !== $currentUser[$field]) {
- $updateData[$field] = $submitted[$field];
- }
+ if ($submitted['name'] !== $currentUser['firstname']) {
+ $updateData['firstname'] = $submitted['name']; // PHP name = DB firstname
}
+ if ($submitted['lastname'] !== $currentUser['name']) {
+ $updateData['name'] = $submitted['lastname']; // PHP lastname = DB name
+ }
+ if ($submitted['email'] !== $currentUser['email']) {
+ $updateData['email'] = $submitted['email'];
+ }
+
+
if ($submitted['password'] !== '') {
- $salt = bin2hex(random_bytes(16));
- $hash = hash('sha256', $submitted['password'] . $salt);
+ $salt = bin2hex(random_bytes(16));
+ $hash = hash('sha256', $submitted['password'] . $salt);
$updateData['passwort'] = $hash;
- $updateData['salt'] = $salt;
+ $updateData['salt'] = $salt;
}
if (empty($updateData)) {
$this->message = 'Keine Änderungen festgestellt.';
- return $this->showUserChangeAccountSettings();
+ $this->view->render('User/showUserChangeAccountSettings');
+ return;
}
$ok = $this->db->updateUserData($userId, $updateData);
if ($ok) {
- // Session‑Werte aktualisieren
$_SESSION['vorname'] = $updateData['name'] ?? $_SESSION['vorname'];
$_SESSION['name'] = $updateData['lastname'] ?? $_SESSION['name'];
$_SESSION['email'] = $updateData['email'] ?? $_SESSION['email'];
$this->message = 'Änderungen erfolgreich gespeichert.';
+
+ header("Location: index.php?controller=user&do=showUserAccountPage");
+ exit();
} else {
$this->errors['general'] = 'Beim Speichern ist ein Fehler aufgetreten.';
+ return;
}
- return $this->showUserChangeAccountSettings();
+ $this->view->render('User/showUserAccountPage');
+ return;
}
diff --git a/Views/User/showUserChangeAccountSettings.phtml b/Views/User/showUserChangeAccountSettings.phtml
index 2d8cf33..aa22ca6 100644
--- a/Views/User/showUserChangeAccountSettings.phtml
+++ b/Views/User/showUserChangeAccountSettings.phtml
@@ -14,9 +14,9 @@ include dirname(__DIR__).'/header.phtml';
-
+
-
+