SignupKey impl
This commit is contained in:
parent
031aebb1d3
commit
ad92a070a1
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
TODO: This needs a re-do. This is one of the first pages on this project
|
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\Moderation\Filter;
|
||||||
use Alphaland\Users\Activation;
|
use Alphaland\Users\Activation;
|
||||||
use Alphaland\Users\ReferralProgram;
|
use Alphaland\Users\ReferralProgram;
|
||||||
|
|
@ -98,7 +99,7 @@ else
|
||||||
{
|
{
|
||||||
$isUserGen = true;
|
$isUserGen = true;
|
||||||
}
|
}
|
||||||
else if (verifySignupKey($signupkey)) //old invite keys from admins
|
else if (SignupKey::ValidateSignupKey($signupkey)) //invite keys from admins
|
||||||
{
|
{
|
||||||
$isAdminGen = true;
|
$isAdminGen = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Alphaland\Administration\SignupKey;
|
||||||
use Alphaland\Web\WebContextManager;
|
use Alphaland\Web\WebContextManager;
|
||||||
|
|
||||||
WebContextManager::ForceHttpsCloudflare();
|
WebContextManager::ForceHttpsCloudflare();
|
||||||
|
|
@ -14,7 +15,7 @@ $alert = "";
|
||||||
$generated_key = "";
|
$generated_key = "";
|
||||||
if(isset($_POST['Submit']))
|
if(isset($_POST['Submit']))
|
||||||
{
|
{
|
||||||
$generated_key = genSignupKey();
|
$generated_key = SignupKey::GenerateSignupKey();
|
||||||
if (!empty($generated_key))
|
if (!empty($generated_key))
|
||||||
{
|
{
|
||||||
$alert = "<div class='alert alert-success' role='alert'>Generated</div>";
|
$alert = "<div class='alert alert-success' role='alert'>Generated</div>";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue