Fix 2 issues on my part

~ Update User.php to fix the PDO accessor thingy

~ Update WebContextManager.php to fix another PDO thingy
This commit is contained in:
Nikita Petko 2021-11-24 19:32:00 +00:00 committed by Github Enterprise
parent c2d8d6878b
commit 3457dd5cb7
2 changed files with 10 additions and 14 deletions

View File

@ -41,7 +41,7 @@ namespace Alphaland\Users {
public function UpdateLastSeen() public function UpdateLastSeen()
{ {
if (!UserModerationManager::IsBanned($this->ID)) { 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->bindParam(":id", $this->ID, PDO::PARAM_INT);
$query->execute(); $query->execute();
} }
@ -52,7 +52,7 @@ namespace Alphaland\Users {
if (!UserModerationManager::IsBanned($this->ID)) { if (!UserModerationManager::IsBanned($this->ID)) {
if (($dailyTime + User::SecondsInDays) < time() || $dailyTime == 0) { if (($dailyTime + User::SecondsInDays) < time() || $dailyTime == 0) {
// it has been a day or this is their first collection. // 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->bindParam(":id", $this->ID, PDO::PARAM_INT);
$query->execute(); $query->execute();
} }
@ -62,7 +62,7 @@ namespace Alphaland\Users {
public function UpdateIpAddress() public function UpdateIpAddress()
{ {
$ip = WebContextManager::GetCurrentIPAddress(); $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(":ip", $ip, PDO::PARAM_STR);
$query->bindParam(":id", $this->ID, PDO::PARAM_INT); $query->bindParam(":id", $this->ID, PDO::PARAM_INT);
$query->execute(); $query->execute();
@ -70,7 +70,7 @@ namespace Alphaland\Users {
public function ValidateToken(string $token): bool 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->bindParam(":tk", $token, PDO::PARAM_STR);
$query->execute(); $query->execute();
@ -86,7 +86,7 @@ namespace Alphaland\Users {
public function Logout() public function Logout()
{ {
if ($this->IsLoggedIn) { 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->bindParam(":id", $this->SessionCookieID, PDO::PARAM_INT);
$query->execute(); $query->execute();
} }
@ -94,7 +94,7 @@ namespace Alphaland\Users {
private function ValidateTokenInternal($session): bool 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->bindParam(":id", $session->uid, PDO::PARAM_INT);
$query->execute(); $query->execute();
@ -126,8 +126,6 @@ namespace Alphaland\Users {
$this->Currency = $userInfo->currency; $this->Currency = $userInfo->currency;
} }
private const SecondsInDays = 86400;
private PDO $pdo = $GLOBALS['pdo'];
private const $SecondsInDays = 86400;
} }
} }

View File

@ -14,7 +14,7 @@ namespace Alphaland\Web {
public static function IsUnderMaintenance(): bool 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(); $query->execute();
if ($query->rowCount() > 0) if ($query->rowCount() > 0)
@ -31,7 +31,7 @@ namespace Alphaland\Web {
if (!WebContextManager::IsUnderMaintenance()) return true; if (!WebContextManager::IsUnderMaintenance()) return true;
if ( if (
!WebContextManager::CurrentUser->IsAdministrator() !WebContextManager::$CurrentUser->IsAdministrator()
&& !WebContextManager::IsCurrentIpAddressWhitelisted() && !WebContextManager::IsCurrentIpAddressWhitelisted()
) return false; ) return false;
@ -46,8 +46,6 @@ namespace Alphaland\Web {
return in_array($currentIp, $ipWhitelist); return in_array($currentIp, $ipWhitelist);
} }
private static PDO $pdo = $GLOBALS['pdo']; public static $CurrentUser = new User();
public static const $CurrentUser = new User();
} }
} }