Update Activation Dependencies
~ Stop instantiating static classes :(((( ~ Naming styles ~ Using HashingUtility instead of functions.php's genHash thing
This commit is contained in:
parent
3457dd5cb7
commit
8ce4eef246
|
|
@ -6,43 +6,41 @@
|
|||
|
||||
namespace Alphaland\Users {
|
||||
|
||||
use Alphaland\Common\HashingUtiltity;
|
||||
use PDO;
|
||||
|
||||
class Activation
|
||||
{
|
||||
private static function generateActivationCode()
|
||||
private static function GenerateActivationCode()
|
||||
{
|
||||
$hash = "";
|
||||
while (true) {
|
||||
$hash = genHash(32);
|
||||
do {
|
||||
$hash = HashingUtiltity::GenerateByteHash(32);
|
||||
|
||||
$keycheck = $GLOBALS['pdo']->prepare("SELECT * FROM `alphaland_verification` WHERE `activationcode` = :ac");
|
||||
$keycheck = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `alphaland_verification` WHERE `activationcode` = :ac");
|
||||
$keycheck->bindParam(":ac", $hash, PDO::PARAM_STR);
|
||||
$keycheck->execute();
|
||||
if ($keycheck->rowCount() == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while($keycheck->fetchColumn(0) != 0);
|
||||
return $hash;
|
||||
}
|
||||
|
||||
public static function getUserActivationCode(int $userid)
|
||||
public static function GetUserActivationCode(int $userid)
|
||||
{
|
||||
$query = $GLOBALS['pdo']->prepare("SELECT * FROM `alphaland_verification` WHERE `uid` = :uid");
|
||||
$query = $GLOBALS['pdo']->prepare("SELECT `activationcode` FROM `alphaland_verification` WHERE `uid` = :uid");
|
||||
$query->bindParam(":uid", $userid, PDO::PARAM_INT);
|
||||
$query->execute();
|
||||
if ($query->rowCount() == 1) {
|
||||
return $query->fetch(PDO::FETCH_OBJ)->activationcode;
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function isUserActivated(int $userid)
|
||||
{
|
||||
$query = $GLOBALS['pdo']->prepare("SELECT * FROM `alphaland_verification` WHERE `isactivated` = 1 AND `uid` = :uid");
|
||||
$query = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `alphaland_verification` WHERE `isactivated` = 1 AND `uid` = :uid");
|
||||
$query->bindParam(":uid", $userid, PDO::PARAM_INT);
|
||||
$query->execute();
|
||||
if ($query->rowCount() > 0) {
|
||||
if ($query->fetchColumn(0) > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -50,8 +48,8 @@ namespace Alphaland\Users {
|
|||
|
||||
public static function setupUserActivation(int $userid) //this should be ran when the user first signs up
|
||||
{
|
||||
if (!Activation::isUserActivated($userid)) {
|
||||
$activationcode = Activation::generateActivationCode();
|
||||
if (!Activation::IsUserActivated($userid)) {
|
||||
$activationcode = Activation::GenerateActivationCode();
|
||||
|
||||
$n = $GLOBALS['pdo']->prepare("INSERT INTO `alphaland_verification`(`activationcode`,`uid`) VALUES(:ac, :userid)");
|
||||
$n->bindParam(":ac", $activationcode, PDO::PARAM_STR);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
my balls yo jaws
|
||||
*/
|
||||
|
||||
use Alphaland\Users\Activation;
|
||||
use Alphaland\Users\TwoFactor;
|
||||
|
||||
try
|
||||
|
|
@ -95,6 +96,7 @@ try
|
|||
include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Users/Activation.php";
|
||||
include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Users/TwoFactor.php";
|
||||
include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Moderation/UserModerationManager.php";
|
||||
include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Common/HashingUtiltity.php"
|
||||
|
||||
//authenticator
|
||||
$authenticator = new PHPGangsta_GoogleAuthenticator();
|
||||
|
|
@ -132,8 +134,7 @@ try
|
|||
forceHttpsCloudflare();
|
||||
}
|
||||
|
||||
$activated = new Alphaland\Users\Activation();
|
||||
$activated = $activated::isUserActivated($GLOBALS['user']->id);
|
||||
$activated = Activation::IsUserActivated($GLOBALS['user']->id);
|
||||
|
||||
$twofactor = TwoFactor::IsSession2FAUnlocked();
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
use Alphaland\Moderation\UserModerationManager;
|
||||
use Alphaland\Users\Activation;
|
||||
|
||||
class user {
|
||||
public $id = -1;
|
||||
|
|
@ -69,8 +70,7 @@ class user {
|
|||
// ..
|
||||
|
||||
//activation stuff
|
||||
$activated = new Alphaland\Users\Activation();
|
||||
$activated = $activated::isUserActivated($this->id);
|
||||
$activated = Activation::IsUserActivated($this->id);
|
||||
|
||||
//banned
|
||||
$banned = UserModerationManager::IsBanned($this->id);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
$activation = new Alphaland\Users\Activation();
|
||||
|
||||
if ($activation::isUserActivated($user->id)) {
|
||||
use Alphaland\Users\Activation;
|
||||
|
||||
if (Activation::IsUserActivated($user->id)) {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
$activationcode = $activation::getUserActivationCode($user->id);
|
||||
$activationcode = Activation::GetUserActivationCode($user->id);
|
||||
|
||||
$body = '
|
||||
<div class="container-fluid" style="display: flex;justify-content: center;align-items: center;text-align: center;min-height: 100vh;">
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
TODO: This needs a re-do. This is one of the first pages on this project
|
||||
*/
|
||||
|
||||
use Alphaland\Users\Activation;
|
||||
|
||||
$body = '';
|
||||
$error = '';
|
||||
|
||||
|
|
@ -130,8 +132,7 @@ else
|
|||
setDefaults($userID); //gives default outfit, body colors and wears the default outfit
|
||||
|
||||
//setup the activation system
|
||||
$activation = new Alphaland\Users\Activation();
|
||||
$activation::setupUserActivation($userID);
|
||||
Activation::SetupUserActivation($userID);
|
||||
|
||||
//create new session
|
||||
createSession($userID);
|
||||
|
|
|
|||
Loading…
Reference in New Issue