SignupKey impl

This commit is contained in:
Astrologies 2021-12-22 05:35:58 -05:00
parent 031aebb1d3
commit ad92a070a1
3 changed files with 47 additions and 2 deletions

View File

@ -0,0 +1,43 @@
<?php
namespace Alphaland\Administration {
use Alphaland\Common\HashingUtiltity;
use PDO;
class SignupKey
{
public static function GenerateSignupKey()
{
$hash = "";
do {
$hash = HashingUtiltity::GenerateByteHash(16);
$tokencheck = $GLOBALS['pdo']->prepare("SELECT * FROM signup_keys WHERE signupkey = :t");
$tokencheck->bindParam(":t", $hash, PDO::PARAM_STR);
$tokencheck->execute();
} while ($tokencheck->fetchColumn() != 0);
$n = $GLOBALS['pdo']->prepare("INSERT INTO signup_keys(signupkey, whenGenerated) VALUES(:t, UNIX_TIMESTAMP())");
$n->bindParam(":t", $hash, PDO::PARAM_STR);
$n->execute();
return $hash;
}
public static function ValidateSignupKey(string $key)
{
$n = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM signup_keys WHERE signupkey = :t");
$n->bindParam(":t", $key, PDO::PARAM_STR);
$n->execute();
if ($n->fetchColumn() > 0) {
$invalidate = $GLOBALS['pdo']->prepare("DELETE FROM signup_keys WHERE signupkey = :t");
$invalidate->bindParam(":t", $key, PDO::PARAM_STR);
$invalidate->execute();
if ($invalidate->rowCount() > 0) {
return true;
}
}
return false;
}
}
}

View File

@ -5,6 +5,7 @@
TODO: This needs a re-do. This is one of the first pages on this project
*/
use Alphaland\Administration\SignupKey;
use Alphaland\Moderation\Filter;
use Alphaland\Users\Activation;
use Alphaland\Users\ReferralProgram;
@ -98,7 +99,7 @@ else
{
$isUserGen = true;
}
else if (verifySignupKey($signupkey)) //old invite keys from admins
else if (SignupKey::ValidateSignupKey($signupkey)) //invite keys from admins
{
$isAdminGen = true;
}

View File

@ -1,5 +1,6 @@
<?php
use Alphaland\Administration\SignupKey;
use Alphaland\Web\WebContextManager;
WebContextManager::ForceHttpsCloudflare();
@ -14,7 +15,7 @@ $alert = "";
$generated_key = "";
if(isset($_POST['Submit']))
{
$generated_key = genSignupKey();
$generated_key = SignupKey::GenerateSignupKey();
if (!empty($generated_key))
{
$alert = "<div class='alert alert-success' role='alert'>Generated</div>";