From d79c8c09a235bb6929cd8228797c17e0a04603dc Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Wed, 22 May 2024 13:32:54 +0400 Subject: [PATCH] use `getSignedInClient` for simplifcation --- src/controllers/Product.php | 11 ++++------- src/controllers/Profile.php | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/controllers/Product.php b/src/controllers/Product.php index d1bcb201..8a2d6096 100644 --- a/src/controllers/Product.php +++ b/src/controllers/Product.php @@ -21,7 +21,7 @@ class Product private ?ProductModel $product = null; // product to be displayed private array $view_data; - private ?User $signed_user = null; // currently logged-in user + private ?User $signed_user; // currently logged-in user public function __construct() { @@ -38,13 +38,10 @@ public function __construct() // get product id from URL $product_id = filter_var(Utility::splitURL()[2], FILTER_VALIDATE_INT); - // check if user is logged in - $reviewer_email = $_SESSION['user'] ?? ""; - // get user details - $user_account = Client::getByEmail($reviewer_email); - if (!empty($user_account)) { - $this->signed_user = $user_account; + $this->signed_user = $this->getSignedInClient(); + + if (!empty($this->signed_user)) { $this->view_data["signed_in_user"] = true; } diff --git a/src/controllers/Profile.php b/src/controllers/Profile.php index d64fd06f..6bd132b4 100644 --- a/src/controllers/Profile.php +++ b/src/controllers/Profile.php @@ -74,7 +74,7 @@ private function handleAccountDeletion(): void */ private function handleUnsignedUsers(): void { - if (!array_key_exists('user', $_SESSION) || !isset($_SESSION['user'])) { + if (empty($this->getSignedInClient())) { Utility::redirect('login'); } }