From 2be9ed5c010a9107d4a349638bfd5b46a26e7395 Mon Sep 17 00:00:00 2001 From: Astrologies Date: Wed, 22 Dec 2021 05:38:01 -0500 Subject: [PATCH] Email impl --- globals/Dependencies/Common/Email.php | 56 +++++++++++++++++++++++++++ html/register.php | 3 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 globals/Dependencies/Common/Email.php diff --git a/globals/Dependencies/Common/Email.php b/globals/Dependencies/Common/Email.php new file mode 100644 index 0000000..6c9113f --- /dev/null +++ b/globals/Dependencies/Common/Email.php @@ -0,0 +1,56 @@ +prepare("SELECT COUNT(*) FROM verify_email_keys WHERE token = :t"); + $tokencheck->bindParam(":t", $hash, PDO::PARAM_STR); + $tokencheck->execute(); + } while ($tokencheck->fetchColumn() != 0); + return $hash; + } + + public static function GenerateResetPasswordHash(int $len) + { + $hash = ""; + do { + $hash = HashingUtiltity::GenerateByteHash($len); + $tokencheck = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM password_reset_keys WHERE token = :t"); + $tokencheck->bindParam(":t", $hash, PDO::PARAM_STR); + $tokencheck->execute(); + } while ($tokencheck->fetchColumn() != 0); + return $hash; + } + + public static function IsEmailRegistered(string $email) + { + $check = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM users WHERE email = :e"); + $check->bindParam(":e", $email, PDO::PARAM_STR); + $check->execute(); + if ($check->fetchColumn() > 0) { + return true; + } + return false; + } + } +} \ No newline at end of file diff --git a/html/register.php b/html/register.php index a81511a..76c0496 100644 --- a/html/register.php +++ b/html/register.php @@ -6,6 +6,7 @@ */ use Alphaland\Administration\SignupKey; +use Alphaland\Common\Email; use Alphaland\Moderation\Filter; use Alphaland\Users\Activation; use Alphaland\Users\ReferralProgram; @@ -77,7 +78,7 @@ else $error = ''; } - if (emailRegistered($email)) + if (Email::IsEmailRegistered($email)) { $error = "Email is already registered"; }