From 3817aac4b94c1c0043095179e957e888537bc2b7 Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Tue, 4 Jun 2024 20:11:27 -0600 Subject: [PATCH 1/2] Middleware de validacion de usuario activo --- app/Http/Middleware/CheckBanned.php | 29 +++++++++++++++++++++++++++++ bootstrap/app.php | 4 +++- routes/web.php | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/Http/Middleware/CheckBanned.php diff --git a/app/Http/Middleware/CheckBanned.php b/app/Http/Middleware/CheckBanned.php new file mode 100644 index 0000000..23db77d --- /dev/null +++ b/app/Http/Middleware/CheckBanned.php @@ -0,0 +1,29 @@ +check() && (auth()->user()->active == 0)){ + auth('web')->logout(); + $request->session()->invalidate(); + $request->session()->regenerateToken(); + return redirect()->route('login')->with('error', 'Your Account is suspended, please contact Admin.'); + } + + return $next($request); + } +} diff --git a/bootstrap/app.php b/bootstrap/app.php index d654276..a4ae0f1 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -4,6 +4,8 @@ use Illuminate\Foundation\Configuration\Exceptions; use Illuminate\Foundation\Configuration\Middleware; +use App\Http\Middleware\CheckBanned; + return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', @@ -12,7 +14,7 @@ health: '/up', ) ->withMiddleware(function (Middleware $middleware) { - // + $middleware->append(CheckBanned::class); }) ->withExceptions(function (Exceptions $exceptions) { // diff --git a/routes/web.php b/routes/web.php index 0b90255..ad319f1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,7 @@ group(function () { Route::get('/dashboard', function () { return view('dashboard'); -- GitLab From 1d34ddf61a10d32c471f3a6838643502c67b1468 Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Tue, 4 Jun 2024 20:48:07 -0600 Subject: [PATCH 2/2] Error de cuenta suspendida en el middleware --- app/Http/Middleware/CheckBanned.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Middleware/CheckBanned.php b/app/Http/Middleware/CheckBanned.php index 23db77d..d4d0a16 100644 --- a/app/Http/Middleware/CheckBanned.php +++ b/app/Http/Middleware/CheckBanned.php @@ -21,7 +21,7 @@ public function handle(Request $request, Closure $next): Response auth('web')->logout(); $request->session()->invalidate(); $request->session()->regenerateToken(); - return redirect()->route('login')->with('error', 'Your Account is suspended, please contact Admin.'); + return redirect()->route('login')->withErrors('Su cuenta está suspendida, póngase en contacto con el administrador del sistema.'); } return $next($request); -- GitLab