Skip to content

Commit

Permalink
use getSignedInClient for simplifcation
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed May 22, 2024
1 parent 8c1f85d commit d79c8c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/controllers/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand Down

0 comments on commit d79c8c0

Please sign in to comment.