From 3d246ccb606e54aa874db27d7dab31673a3945c2 Mon Sep 17 00:00:00 2001 From: Illia Hromovoi Date: Wed, 25 Jun 2025 09:59:58 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Benutzeranmeldungsfunktionlit=C3=A4t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CSS/style.css | 1 - Controller/UserController.php | 41 +++++++++++++++++++++++---- Model/UserModel.php | 12 ++++++-- Views/User/showUserConfirmation.phtml | 11 ------- 4 files changed, 45 insertions(+), 20 deletions(-) delete mode 100644 Views/User/showUserConfirmation.phtml diff --git a/CSS/style.css b/CSS/style.css index 08bea58..4471da7 100644 --- a/CSS/style.css +++ b/CSS/style.css @@ -21,7 +21,6 @@ body { } h1 { - margin: 10px; color: var(--brand-white); font-size: var(--font-size-title-h1); } diff --git a/Controller/UserController.php b/Controller/UserController.php index 463c83a..a58a4fc 100644 --- a/Controller/UserController.php +++ b/Controller/UserController.php @@ -19,7 +19,7 @@ class UserController{ } - public function showUserConfirmation(){ + public function showUserRegisterConfirmation(){ } @@ -27,10 +27,20 @@ class UserController{ } + public function showUserLoginConfirmation(){ + $userId = $this->getCurrentUserId(); + $user = null; + var_dump($user . "user"); + if($userId){ + $user = $this->db->getUserById($userId); + } + include 'Views/User/showUserLoginConfirmation.phtml'; + } + public function register(){ $this->db->createUser($_POST); - $this->view->setDoMethodName("showUserConfirmation"); - $this->showUserConfirmation(); + $this->view->setDoMethodName("showUserRegisterConfirmation"); + $this->showUserRegisterConfirmation(); } public function login(){ @@ -43,13 +53,32 @@ class UserController{ $hash = hash('sha256', $_POST["password"] . $user["salt"]); if($hash == $user["passwort"]){ - $_SESSION["user_id"] = $user["id"]; - $_SESSION["user_role"] = $user["role"]; - echo "Login ergolgreich"; + $this->setUserSession($user); + $this->showUserLoginConfirmation(); }else{ echo "Falsches Passwort"; } + } + public function setUserSession(array $user){ + $_SESSION["user_id"] = $user["id"]; + $_SESSION["user_role"] = $user["role"]; + } + public function clearUserSession(){ + unset($_SESSION["user_id"], $_SESSION["user_role"]); + } + + public function logout(){ + $this->clearUserSession(); + echo "Erfolgreich ausgeloggt"; + } + + public function isUserLoggenIn(){ + return isset($_SESSION["user_id"]); + } + + public function getCurrentUserId(){ + return $_SESSION["user_id"] ?? null; } } \ No newline at end of file diff --git a/Model/UserModel.php b/Model/UserModel.php index ed2a2de..83973fd 100644 --- a/Model/UserModel.php +++ b/Model/UserModel.php @@ -28,8 +28,8 @@ class UserModel extends Database $sth = $pdo->prepare($sql); $sth->execute([ ":guid" => $guid, - ":name" => $values["name"], - ":firstname" => $values["lastname"], + ":name" => $values["lastname"], + ":firstname" => $values["name"], ":email" => $values["email"], ":password" => $hash, ":salt" => $salt, @@ -51,4 +51,12 @@ class UserModel extends Database return $sth->fetch(); } + public function getUserById($id){ + $pdo = $this->linkDB(); + $sql = "SELECT * FROM user WHERE id = :id"; + $sth = $pdo->prepare($sql); + $sth->execute([":id" => $id]); + return $sth->fetch(); + } + } \ No newline at end of file diff --git a/Views/User/showUserConfirmation.phtml b/Views/User/showUserConfirmation.phtml deleted file mode 100644 index 2788b36..0000000 --- a/Views/User/showUserConfirmation.phtml +++ /dev/null @@ -1,11 +0,0 @@ - - -

Sie haben sich erfolgreich registriert

- - - - From 3ac0217f9a4d95b72d9cf5e5ea60de5c12f15bbb Mon Sep 17 00:00:00 2001 From: Illia Hromovoi Date: Wed, 25 Jun 2025 10:01:42 +0200 Subject: [PATCH 2/2] fehlende templates --- Views/User/showUserLoginConfirmation.phtml | 17 +++++++++++++++++ Views/User/showUserRegisterConfirmation.phtml | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 Views/User/showUserLoginConfirmation.phtml create mode 100644 Views/User/showUserRegisterConfirmation.phtml diff --git a/Views/User/showUserLoginConfirmation.phtml b/Views/User/showUserLoginConfirmation.phtml new file mode 100644 index 0000000..d5289c1 --- /dev/null +++ b/Views/User/showUserLoginConfirmation.phtml @@ -0,0 +1,17 @@ + + + +

Hallo, !

+ +

Benutzerdaten konnten nicht geladen werden.

+ + +

Sie haben sich erfolgreich angemeldet

+ + + + diff --git a/Views/User/showUserRegisterConfirmation.phtml b/Views/User/showUserRegisterConfirmation.phtml new file mode 100644 index 0000000..2788b36 --- /dev/null +++ b/Views/User/showUserRegisterConfirmation.phtml @@ -0,0 +1,11 @@ + + +

Sie haben sich erfolgreich registriert

+ + + +