diff --git a/src/controllers/Product.php b/src/controllers/Product.php index d1bcb20..8a2d609 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 d64fd06..6bd132b 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'); } }