From ac310dce99fe3b2cd7e5618889fac9fc001b43e3 Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 7 Dec 2016 16:33:26 +0100 Subject: [PATCH] remove rank based activation --- app/Console/Command/SetupCommand.php | 18 ------------- app/Controllers/AuthController.php | 25 ++++++------------- app/Controllers/MetaController.php | 8 ++++-- .../Settings/AccountController.php | 1 - app/User.php | 10 +++++--- config/config.example.ini | 15 ++++++----- 6 files changed, 26 insertions(+), 51 deletions(-) diff --git a/app/Console/Command/SetupCommand.php b/app/Console/Command/SetupCommand.php index 1a2745a..3bcac14 100644 --- a/app/Console/Command/SetupCommand.php +++ b/app/Console/Command/SetupCommand.php @@ -44,14 +44,6 @@ class SetupCommand extends Command // Rank data (uses column names) $ranks = [ - [ - 'rank_hierarchy' => 0, - 'rank_name' => 'Inactive', - 'rank_hidden' => 1, - 'rank_colour' => '#555', - 'rank_description' => 'Users that are yet to be activated or have deactivated their account.', - 'rank_title' => 'Inactive', - ], [ 'rank_hierarchy' => 1, 'rank_name' => 'Normal user', @@ -225,16 +217,6 @@ class SetupCommand extends Command // Forum permission data $forum_perms = [ - [ - 'forum_id' => 1, - 'rank_id' => config('rank.inactive'), - 'perm_view' => true, - ], - [ - 'forum_id' => 3, - 'rank_id' => config('rank.inactive'), - 'perm_view' => false, - ], [ 'forum_id' => 1, 'rank_id' => config('rank.regular'), diff --git a/app/Controllers/AuthController.php b/app/Controllers/AuthController.php index ee7dfb2..d472fb8 100644 --- a/app/Controllers/AuthController.php +++ b/app/Controllers/AuthController.php @@ -238,24 +238,18 @@ class AuthController extends Controller return view('global/information', compact('message', 'redirect')); } - // Set a few variables - $requireActive = config('user.require_activation'); - $ranks = $requireActive ? [config('rank.inactive')] : [config('rank.regular')]; - - // Create the user - $user = User::create($username, $password, $email, $ranks); + $requireActive = boolval(config('user.require_activation')); + $user = User::create($username, $password, $email, !$requireActive); // Check if we require e-mail activation if ($requireActive) { - // Send activation e-mail to user $this->sendActivationMail($user); } // Return true with a specific message if needed $redirect = route('auth.login'); - $message = $requireActive - ? 'Your registration went through! An activation e-mail has been sent.' - : 'Your registration went through! Welcome to ' . config('general.name') . '!'; + $message = 'Your registration went through!'; + $message .= $requireActive ? ' An activation e-mail has been sent.' : ' Welcome to ' . config('general.name') . '!'; return view('global/information', compact('message', 'redirect')); } @@ -296,14 +290,9 @@ class AuthController extends Controller return view('global/information', compact('message', 'redirect')); } - // Get the ids for deactivated and default user ranks - $rankDefault = config('rank.regular'); - $rankDeactive = config('rank.inactive'); - - // Add normal user, remove deactivated and set normal as default - $user->addRanks([$rankDefault]); - $user->setMainRank($rankDefault); - $user->removeRanks([$rankDeactive]); + DB::table('users') + ->where('user_id', $userId) + ->update(['user_activated' => 1]); $redirect = route('auth.login'); $message = "Your account is activated, welcome to " . config('general.name') . "!"; diff --git a/app/Controllers/MetaController.php b/app/Controllers/MetaController.php index 2325f10..71c640e 100644 --- a/app/Controllers/MetaController.php +++ b/app/Controllers/MetaController.php @@ -27,7 +27,9 @@ class MetaController extends Controller { // Get the newest user $newestUserId = DB::table('users') - ->whereNotIn('rank_main', [config('rank.banned'), config('rank.inactive')]) + ->where('rank_main', '!=', config('rank.banned')) + ->where('user_activated', 1) + ->where('user_restricted', 0) ->orderBy('user_id', 'desc') ->limit(1) ->get(['user_id']); @@ -64,7 +66,9 @@ class MetaController extends Controller 'news' => $news->posts(3), 'stats' => [ 'userCount' => DB::table('users') - ->whereNotIn('rank_main', [config('rank.banned'), config('rank.inactive')]) + ->where('rank_main', '!=', config('rank.banned')) + ->where('user_activated', 1) + ->where('user_restricted', 0) ->count(), 'newestUser' => $newestUser, 'lastRegDate' => date_diff( diff --git a/app/Controllers/Settings/AccountController.php b/app/Controllers/Settings/AccountController.php index 05540be..104b248 100644 --- a/app/Controllers/Settings/AccountController.php +++ b/app/Controllers/Settings/AccountController.php @@ -238,7 +238,6 @@ class AccountController extends Controller $mode = $_POST['mode'] ?? null; $locked = [ - config('rank.inactive'), config('rank.regular'), config('rank.premium'), config('rank.alumni'), diff --git a/app/User.php b/app/User.php index 14efd7c..e293673 100644 --- a/app/User.php +++ b/app/User.php @@ -274,13 +274,10 @@ class User */ public static function construct($uid, bool $forceRefresh = false): User { - // Check if a user object isn't present in cache if ($forceRefresh || !array_key_exists($uid, self::$userCache)) { - // If not create a new object and cache it self::$userCache[$uid] = new User($uid); } - // Return the cached object return self::$userCache[$uid]; } @@ -292,12 +289,16 @@ class User * @param array $ranks * @return User */ - public static function create(string $username, string $password, string $email, array $ranks = [2]): User + public static function create(string $username, string $password, string $email, bool $active = true, array $ranks = []): User { $usernameClean = clean_string($username, true); $emailClean = clean_string($email, true); $password = password_hash($password, PASSWORD_BCRYPT); + if (!$ranks) { + $ranks[] = config('rank.regular'); + } + $userId = DB::table('users') ->insertGetId([ 'username' => $username, @@ -310,6 +311,7 @@ class User 'user_registered' => time(), 'user_last_online' => 0, 'user_country' => get_country_code(), + 'user_activated' => $active, ]); $user = static::construct($userId); diff --git a/config/config.example.ini b/config/config.example.ini index b6cdfcc..ff5a53b 100644 --- a/config/config.example.ini +++ b/config/config.example.ini @@ -177,14 +177,13 @@ secret_id = ; Ranks ids, these ranks are used by automated procedures in the backend ; If you're using the setup command in mahou these are already set correctly for you! [rank] -inactive = 1 -regular = 2 -mod = 3 -admin = 4 -bot = 5 -premium = 6 -alumni = 7 -banned = 8 +regular = 1 +mod = 2 +admin = 3 +bot = 4 +premium = 5 +alumni = 6 +banned = 7 ; Forum settings [forum]