diff --git a/CSS/style.css b/CSS/style.css index c7267d5..0c3d47a 100644 --- a/CSS/style.css +++ b/CSS/style.css @@ -20,7 +20,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/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, = htmlspecialchars($user['vorname']) ?> = htmlspecialchars($user['name']) ?>!
+ +Benutzerdaten konnten nicht geladen werden.
+ + +