From 29db0ae8b6e1433a0a9014100e617e9d15270691 Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Tue, 4 Feb 2025 10:31:11 +0200 Subject: [PATCH] Added ability to have different user statuses --- cp/app/Auth/Auth.php | 17 ++++++++ cp/app/Controllers/UsersController.php | 6 ++- .../views/admin/users/createUser.twig | 4 +- .../views/admin/users/updateUser.twig | 7 +++- cp/resources/views/partials/js-users.twig | 39 +++++++++++++++---- 5 files changed, 60 insertions(+), 13 deletions(-) diff --git a/cp/app/Auth/Auth.php b/cp/app/Auth/Auth.php index 93f9b4a..8034e60 100644 --- a/cp/app/Auth/Auth.php +++ b/cp/app/Auth/Auth.php @@ -144,6 +144,23 @@ class Auth $auth->login($email, $password, $rememberDuration); + if ($auth->isArchived()) { + self::$auth->logOut(); + redirect()->route('login')->with('error','User has been archived, please contact registry support'); + } + if ($auth->isBanned()) { + self::$auth->logOut(); + redirect()->route('login')->with('error','User has been banned, please contact registry support'); + } + if ($auth->isPendingReview()) { + self::$auth->logOut(); + redirect()->route('login')->with('error','User is pending review, please contact registry support'); + } + if ($auth->isSuspended()) { + self::$auth->logOut(); + redirect()->route('login')->with('error','User has been suspended, please contact registry support'); + } + // check if a valid code is provided global $container; $db = $container->get('db'); diff --git a/cp/app/Controllers/UsersController.php b/cp/app/Controllers/UsersController.php index 5661ab1..4046c49 100644 --- a/cp/app/Controllers/UsersController.php +++ b/cp/app/Controllers/UsersController.php @@ -47,7 +47,7 @@ class UsersController extends Controller 'username' => v::regex('/^[a-zA-Z0-9_-]+$/')->length(3, 20)->setName('Username'), 'password' => v::stringType()->notEmpty()->length(6, 255)->setName('Password'), 'password_confirmation' => v::equals($data['password'] ?? '')->setName('Password Confirmation'), - 'status' => v::in(['active', 'inactive'])->setName('Status'), + 'status' => v::in(['0', '4'])->setName('Status'), 'role' => v::in(['admin', 'registrar'])->setName('Role'), ]; @@ -105,6 +105,7 @@ class UsersController extends Controller 'username' => $username, 'verified' => $verified, 'roles_mask' => 6, + 'status' => $status, 'registered' => \time() ] ); @@ -141,6 +142,7 @@ class UsersController extends Controller 'username' => $username, 'verified' => $verified, 'roles_mask' => 0, + 'status' => $status, 'registered' => \time() ] ); @@ -243,7 +245,7 @@ class UsersController extends Controller $validators = [ 'email' => v::email()->notEmpty()->setName('Email'), 'username' => v::regex('/^[a-zA-Z0-9_-]+$/')->length(3, 20)->setName('Username'), - 'status' => v::in(['0', '1'])->setName('Status'), + 'status' => v::in(['0', '1', '2', '3', '4', '5'])->setName('Status'), 'verified' => v::in(['0', '1'])->setName('Verified'), // Ensure verified is checked as 0 or 1 ]; diff --git a/cp/resources/views/admin/users/createUser.twig b/cp/resources/views/admin/users/createUser.twig index b06f5e6..339913a 100644 --- a/cp/resources/views/admin/users/createUser.twig +++ b/cp/resources/views/admin/users/createUser.twig @@ -71,8 +71,8 @@