From 0f16293f4e400bf64ab20b0fd51c88a0d369fe8f Mon Sep 17 00:00:00 2001 From: grandeljay Date: Wed, 30 Aug 2023 15:06:56 +0200 Subject: [PATCH] fix: getting user id --- src/api/wishlists-saved.php | 2 +- src/api/wishlists.php | 8 ++++---- src/classes/wishthis/User.php | 4 ++++ src/classes/wishthis/Wish.php | 2 +- src/pages/home.php | 2 +- src/pages/login.php | 4 ++-- src/pages/parts/wishlist.php | 2 +- src/pages/profile.php | 16 ++++++---------- src/pages/register.php | 2 +- src/pages/wishlist.php | 4 ++-- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/api/wishlists-saved.php b/src/api/wishlists-saved.php index bf7cb107..90102a55 100644 --- a/src/api/wishlists-saved.php +++ b/src/api/wishlists-saved.php @@ -62,7 +62,7 @@ switch ($_SERVER['REQUEST_METHOD']) { :wishlist_id );', array( - 'user_id' => $user->id, + 'user_id' => $user->getId(), 'wishlist_id' => Sanitiser::getNumber($_POST['wishlist']), ) ); diff --git a/src/api/wishlists.php b/src/api/wishlists.php index 6efa5e04..1424dd3d 100644 --- a/src/api/wishlists.php +++ b/src/api/wishlists.php @@ -14,11 +14,11 @@ $user = User::getCurrent(); switch ($_SERVER['REQUEST_METHOD']) { case 'POST': - if (isset($_POST['wishlist-name'], $user->id)) { + if (isset($_POST['wishlist-name'], $user->getId())) { /** * Create */ - $user_id = Sanitiser::getNumber($user->id); + $user_id = Sanitiser::getNumber($user->getId()); $wishlist_name = Sanitiser::getTitle($_POST['wishlist-name']); $wishlist_hash = sha1(time() . $user_id . $wishlist_name); @@ -136,7 +136,7 @@ switch ($_SERVER['REQUEST_METHOD']) { if ($wishlist->exists) { /** Determine if user is allowed to access wishlist */ - if ($user->isLoggedIn() && $user->id === $wishlist->user) { + if ($user->isLoggedIn() && $user->getId() === $wishlist->user) { $response['results'] = $wishlist; } else { http_response_code(403); @@ -155,7 +155,7 @@ switch ($_SERVER['REQUEST_METHOD']) { } else { http_response_code(404); } - } elseif (isset($_GET['userid']) || isset($user->id)) { + } elseif (isset($_GET['userid']) || isset($user->getId())) { /** * Get user wishlists */ diff --git a/src/classes/wishthis/User.php b/src/classes/wishthis/User.php index aa2f37d4..775a63bd 100644 --- a/src/classes/wishthis/User.php +++ b/src/classes/wishthis/User.php @@ -457,6 +457,10 @@ class User ); } + public function getId(): int { + return $this->id; + } + public function getEmail(): string { return $this->email; } diff --git a/src/classes/wishthis/Wish.php b/src/classes/wishthis/Wish.php index aeb5b45c..59500a6e 100644 --- a/src/classes/wishthis/Wish.php +++ b/src/classes/wishthis/Wish.php @@ -197,7 +197,7 @@ class Wish $userCard->getLocale() . '@currency=' . $userCard->getCurrency(), \NumberFormatter::CURRENCY ); - $userIsCurrent = isset($userCurrent->id) && $userCurrent->id === $userCard->id; + $userIsCurrent = isset($userCurrent->getId()) && $userCurrent->getId() === $userCard->getId(); /** * Card diff --git a/src/pages/home.php b/src/pages/home.php index 2505caed..2964cd09 100644 --- a/src/pages/home.php +++ b/src/pages/home.php @@ -49,7 +49,7 @@ $user = User::getCurrent(); ORDER BY `wishes`.`edited` DESC LIMIT 1;', array( - 'user_id' => $user->id, + 'user_id' => $user->getId(), ) ); diff --git a/src/pages/login.php b/src/pages/login.php index a74c26b9..5d608f44 100644 --- a/src/pages/login.php +++ b/src/pages/login.php @@ -52,7 +52,7 @@ if (isset($_POST['reset'], $_POST['email'])) { $user = false !== $userQuery ? new User($userQuery->fetch()) : new User(); - if (isset($user->id)) { + if (isset($user->getId())) { $token = sha1(time() . rand(0, 999999)); $validUntil = time() + 3600; @@ -61,7 +61,7 @@ if (isset($_POST['reset'], $_POST['email'])) { 'UPDATE `users` SET `password_reset_token` = :user_password_reset_token, `password_reset_valid_until` = :user_reset_valid_until - WHERE `id` = ' . $user->id . ';', + WHERE `id` = ' . $user->getId() . ';', array( 'user_password_reset_token' => $token, 'user_reset_valid_until' => date('Y-m-d H:i:s', $validUntil), diff --git a/src/pages/parts/wishlist.php b/src/pages/parts/wishlist.php index f8bf131c..67f8f60c 100644 --- a/src/pages/parts/wishlist.php +++ b/src/pages/parts/wishlist.php @@ -10,7 +10,7 @@ $user = User::getCurrent(); ?> isLoggedIn()) { ?> - +
diff --git a/src/pages/profile.php b/src/pages/profile.php index 6b3c951d..401c920d 100644 --- a/src/pages/profile.php +++ b/src/pages/profile.php @@ -218,7 +218,7 @@ $page->navigation();
- +
@@ -284,7 +284,7 @@ $page->navigation();
- +
@@ -347,7 +347,7 @@ $page->navigation();
- +
@@ -447,7 +447,7 @@ $page->navigation();
- + @@ -512,17 +512,13 @@ $page->navigation();
- +
- id) ? $user : new User(); - ?> - advertisements) { ?> @@ -563,7 +559,7 @@ $page->navigation();
- +
diff --git a/src/pages/register.php b/src/pages/register.php index baf17e36..de14b1a6 100644 --- a/src/pages/register.php +++ b/src/pages/register.php @@ -93,7 +93,7 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { WHERE `id` = :user_id;', array( 'user_password' => User::passwordToHash($_POST['password']), - 'user_id' => $user->id, + 'user_id' => $user->getId(), ) ); diff --git a/src/pages/wishlist.php b/src/pages/wishlist.php index 2f2ff097..624751bb 100644 --- a/src/pages/wishlist.php +++ b/src/pages/wishlist.php @@ -35,7 +35,7 @@ $user = User::getCurrent();
- isLoggedIn() && $user->id !== $wishlist->user) { ?> + isLoggedIn() && $user->getId() !== $wishlist->user) { ?>