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