diff --git a/globals/Dependencies/Users/Activation.php b/globals/Dependencies/Users/Activation.php index 10aaaee..ea125d9 100644 --- a/globals/Dependencies/Users/Activation.php +++ b/globals/Dependencies/Users/Activation.php @@ -6,57 +6,54 @@ namespace Alphaland\Users { - use Alphaland\Common\HashingUtiltity; use PDO; class Activation { - - private static PDO $pdo = $GLOBALS['pdo']; - - private static function GenerateActivationCode(): string + private function generateActivationCode() { $hash = ""; - do { - $hash = HashingUtiltity::GenerateByteHash(32); + while (true) { + $hash = genHash(32); - $query = Activation::$pdo->prepare("SELECT COUNT(*) FROM `alphaland_verification` WHERE `activationcode` = :ac"); - $query->bindParam(":ac", $hash, PDO::PARAM_STR); - $query->execute(); - } while ($query->fetchColumn(0) != 0); - + $keycheck = $GLOBALS['pdo']->prepare("SELECT * FROM `alphaland_verification` WHERE `activationcode` = :ac"); + $keycheck->bindParam(":ac", $hash, PDO::PARAM_STR); + $keycheck->execute(); + if ($keycheck->rowCount() == 0) { + break; + } + } return $hash; } - public static function GetUserActivationCode(int $userid): string + public function getUserActivationCode(int $userid) { - $query = Activation::$pdo->prepare("SELECT `activationcode` FROM `alphaland_verification` WHERE `uid` = :uid"); + $query = $GLOBALS['pdo']->prepare("SELECT * FROM `alphaland_verification` WHERE `uid` = :uid"); $query->bindParam(":uid", $userid, PDO::PARAM_INT); $query->execute(); - if ($query->rowCount() == 1) { - return (string)$query->fetch(PDO::FETCH_OBJ)->activationcode; + return $query->fetch(PDO::FETCH_OBJ)->activationcode; } - return null; + return false; } - public static function IsUserActivated(int $userid): bool + public function isUserActivated(int $userid) { - $query = Activation::$pdo->prepare("SELECT COUNT(*) FROM `alphaland_verification` WHERE `isactivated` = 1 AND `uid` = :uid"); + $query = $GLOBALS['pdo']->prepare("SELECT * FROM `alphaland_verification` WHERE `isactivated` = 1 AND `uid` = :uid"); $query->bindParam(":uid", $userid, PDO::PARAM_INT); $query->execute(); - if ($query->fetchColumn(0) > 0) { + if ($query->rowCount() > 0) { return true; } return false; } - public static function SetupUserActivation(int $userid): bool //this should be ran when the user first signs up + public function setupUserActivation(int $userid) //this should be ran when the user first signs up { - if (!Activation::IsUserActivated($userid)) { - $activationcode = Activation::GenerateActivationCode(); + if (!$this->isUserActivated($userid)) { + $activationcode = $this->generateActivationCode(); - $n = Activation::$pdo->prepare("INSERT INTO `alphaland_verification`(`activationcode`,`uid`) VALUES(:ac, :userid)"); + $n = $GLOBALS['pdo']->prepare("INSERT INTO `alphaland_verification`(`activationcode`,`uid`) VALUES(:ac, :userid)"); $n->bindParam(":ac", $activationcode, PDO::PARAM_STR); $n->bindParam(":userid", $userid, PDO::PARAM_INT); $n->execute();