Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logg out inactive users, and redirected them to the login page #683

Open
wants to merge 2 commits into
base: 5.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Http/Controllers/Configuration/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
47 changes: 47 additions & 0 deletions src/Http/Middleware/UserActive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of SeAT
*
* Copyright (C) 2015 to present Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace Seat\Web\Http\Middleware;

use Closure;

class UserActive
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*
* @throws \Seat\Services\Exceptions\SettingException
*/
public function handle($request, Closure $next)
{

if (! auth()->user()->isActive())
return redirect()->guest('auth/logout')
->with('error', 'Account is administratively disabled.');

return $next($request);
}
}
2 changes: 1 addition & 1 deletion src/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 5 additions & 0 deletions src/WebServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down