diff --git a/src/Http/Controllers/Configuration/UserController.php b/src/Http/Controllers/Configuration/UserController.php index 8a53d077b..38c0eace5 100644 --- a/src/Http/Controllers/Configuration/UserController.php +++ b/src/Http/Controllers/Configuration/UserController.php @@ -153,7 +153,20 @@ public function editUserAccountStatus(int $user_id) { $user = User::findOrFail($user_id); - $user->active = $user->active == false ? true : false; + if ($user->active == true){ + $user->active = false; + event('security.log', [ + 'deactivated account for user ' . $user->name, + 'userstatus', + ]); + } else { + $user->active = true; + event('security.log', [ + 'reactivated account for user ' . $user->name, + 'userstatus', + ]); + } + $user->save(); return redirect()->back() diff --git a/src/Http/Middleware/UserActive.php b/src/Http/Middleware/UserActive.php new file mode 100644 index 000000000..f5b3a01f1 --- /dev/null +++ b/src/Http/Middleware/UserActive.php @@ -0,0 +1,47 @@ +user()->isActive()) + return redirect()->guest('auth/logout') + ->with('error', 'Account is administratively disabled.'); + + return $next($request); + } +} diff --git a/src/Http/routes.php b/src/Http/routes.php index 0a3f7a902..6c94876d8 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -46,7 +46,7 @@ // All routes from here require *at least* that the // user is authenticated. We also run the localization // related logic here for translation support. - Route::group(['middleware' => ['auth', 'locale']], function () { + Route::group(['middleware' => ['auth', 'locale', 'user.active']], function () { // The home route does not need any prefixes // and or namespacing modifications, so we will diff --git a/src/Models/User.php b/src/Models/User.php index 519a882f1..f04463219 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -261,4 +261,14 @@ public function isAdmin(): bool { return $this->admin === true; } + + /** + * Return whether the user is active or not. + * + * @return bool + */ + public function isActive(): bool + { + return $this->active === true; + } } diff --git a/src/WebServiceProvider.php b/src/WebServiceProvider.php index 8c2a918ed..e4cc29787 100644 --- a/src/WebServiceProvider.php +++ b/src/WebServiceProvider.php @@ -59,6 +59,7 @@ use Seat\Web\Http\Middleware\Locale; use Seat\Web\Http\Middleware\RegistrationAllowed; use Seat\Web\Http\Middleware\Requirements; +use Seat\Web\Http\Middleware\UserActive; use Seat\Web\Models\Squads\SquadMember; use Seat\Web\Models\Squads\SquadRole; use Seat\Web\Observers\CharacterAffiliationObserver; @@ -275,6 +276,10 @@ private function add_middleware(Router $router) // Registration Middleware checks of the app is // allowing new user registration to occur. $router->aliasMiddleware('registration.status', RegistrationAllowed::class); + + // UserActive Middleware checks if the user is active + // and redirects them to the login page if not. + $router->aliasMiddleware('user.active', UserActive::class); } /**