remove rank based activation
This commit is contained in:
parent
dd35ceb85f
commit
ac310dce99
6 changed files with 26 additions and 51 deletions
|
@ -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'),
|
||||
|
|
|
@ -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') . "!";
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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'),
|
||||
|
|
10
app/User.php
10
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);
|
||||
|
|
|
@ -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]
|
||||
|
|
Reference in a new issue