From 3457dd5cb75bf977c75c28672ecddadc5014ad24 Mon Sep 17 00:00:00 2001 From: Nikita Petko Date: Wed, 24 Nov 2021 19:32:00 +0000 Subject: [PATCH] Fix 2 issues on my part ~ Update User.php to fix the PDO accessor thingy ~ Update WebContextManager.php to fix another PDO thingy --- globals/Dependencies/Users/User.php | 16 +++++++--------- globals/Dependencies/Web/WebContextManager.php | 8 +++----- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/globals/Dependencies/Users/User.php b/globals/Dependencies/Users/User.php index 50b31a5..e4f940e 100644 --- a/globals/Dependencies/Users/User.php +++ b/globals/Dependencies/Users/User.php @@ -41,7 +41,7 @@ namespace Alphaland\Users { public function UpdateLastSeen() { if (!UserModerationManager::IsBanned($this->ID)) { - $query = $this->pdo->prepare("UPDATE `users` SET `lastseen` = UNIX_TIMESTAMP() WHERE `id` = :id"); + $query = $GLOBALS['pdo']->prepare("UPDATE `users` SET `lastseen` = UNIX_TIMESTAMP() WHERE `id` = :id"); $query->bindParam(":id", $this->ID, PDO::PARAM_INT); $query->execute(); } @@ -52,7 +52,7 @@ namespace Alphaland\Users { if (!UserModerationManager::IsBanned($this->ID)) { if (($dailyTime + User::SecondsInDays) < time() || $dailyTime == 0) { // it has been a day or this is their first collection. - $query = $this->pdo->prepare("UPDATE `users` SET `dailytime` = UNIX_TIMESTAMP(), `currency` = (`currency` + 20) WHERE `id` = :id"); + $query = $GLOBALS['pdo']->prepare("UPDATE `users` SET `dailytime` = UNIX_TIMESTAMP(), `currency` = (`currency` + 20) WHERE `id` = :id"); $query->bindParam(":id", $this->ID, PDO::PARAM_INT); $query->execute(); } @@ -62,7 +62,7 @@ namespace Alphaland\Users { public function UpdateIpAddress() { $ip = WebContextManager::GetCurrentIPAddress(); - $query = $this->pdo->prepare("UPDATE `users` SET `ip` = :ip WHERE `id` = :id"); + $query = $GLOBALS['pdo']->prepare("UPDATE `users` SET `ip` = :ip WHERE `id` = :id"); $query->bindParam(":ip", $ip, PDO::PARAM_STR); $query->bindParam(":id", $this->ID, PDO::PARAM_INT); $query->execute(); @@ -70,7 +70,7 @@ namespace Alphaland\Users { public function ValidateToken(string $token): bool { - $query = $this->pdo->prepare("SELECT * FROM `users` WHERE `id` = :id"); + $query = $GLOBALS['pdo']->prepare("SELECT * FROM `users` WHERE `id` = :id"); $query->bindParam(":tk", $token, PDO::PARAM_STR); $query->execute(); @@ -86,7 +86,7 @@ namespace Alphaland\Users { public function Logout() { if ($this->IsLoggedIn) { - $query = $this->pdo->prepare("UPDATE `sessions` SET `valid` = 0 WHERE `id` = :id"); + $query = $GLOBALS['pdo']->prepare("UPDATE `sessions` SET `valid` = 0 WHERE `id` = :id"); $query->bindParam(":id", $this->SessionCookieID, PDO::PARAM_INT); $query->execute(); } @@ -94,7 +94,7 @@ namespace Alphaland\Users { private function ValidateTokenInternal($session): bool { - $query = $this->pdo->prepare("SELECT * FROM users WHERE id = :id"); + $query = $GLOBALS['pdo']->prepare("SELECT * FROM users WHERE id = :id"); $query->bindParam(":id", $session->uid, PDO::PARAM_INT); $query->execute(); @@ -126,8 +126,6 @@ namespace Alphaland\Users { $this->Currency = $userInfo->currency; } - - private PDO $pdo = $GLOBALS['pdo']; - private const $SecondsInDays = 86400; + private const SecondsInDays = 86400; } } diff --git a/globals/Dependencies/Web/WebContextManager.php b/globals/Dependencies/Web/WebContextManager.php index b151273..daca1c8 100644 --- a/globals/Dependencies/Web/WebContextManager.php +++ b/globals/Dependencies/Web/WebContextManager.php @@ -14,7 +14,7 @@ namespace Alphaland\Web { public static function IsUnderMaintenance(): bool { - $query = WebContextManager::$pdo->prepare("SELECT * FROM `websettings` WHERE `maintenance` = 1"); + $query = $GLOBALS['pdo']->prepare("SELECT * FROM `websettings` WHERE `maintenance` = 1"); $query->execute(); if ($query->rowCount() > 0) @@ -31,7 +31,7 @@ namespace Alphaland\Web { if (!WebContextManager::IsUnderMaintenance()) return true; if ( - !WebContextManager::CurrentUser->IsAdministrator() + !WebContextManager::$CurrentUser->IsAdministrator() && !WebContextManager::IsCurrentIpAddressWhitelisted() ) return false; @@ -46,8 +46,6 @@ namespace Alphaland\Web { return in_array($currentIp, $ipWhitelist); } - private static PDO $pdo = $GLOBALS['pdo']; - - public static const $CurrentUser = new User(); + public static $CurrentUser = new User(); } }