diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index c34cdcf..2173a97 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -61,7 +61,7 @@ class Kernel extends HttpKernel 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class, 'signed' => \App\Http\Middleware\ValidateSignature::class, - 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, - 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, + 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequestsWithRedis::class, + 'verified' => \App\Http\Middleware\EnsureUserIsVerified::class, ]; } diff --git a/app/Http/Middleware/EnsureUserIsVerified.php b/app/Http/Middleware/EnsureUserIsVerified.php new file mode 100644 index 0000000..1f81865 --- /dev/null +++ b/app/Http/Middleware/EnsureUserIsVerified.php @@ -0,0 +1,43 @@ +user()) { + return $request->expectsJson() + ? abort(403) + : Redirect::guest(URL::route($redirectToRoute ?: 'verification.notice')); + } + + + if ($request->user() instanceof MustVerifyEmail && ! $request->user()->hasVerifiedEmail()) { + return $request->expectsJson() + ? abort(403, 'Your email address is not verified.') + : Redirect::guest(URL::route($redirectToRoute ?: 'verification.notice')); + } + + if ($request->user()->is_active === false) { + return $request->expectsJson() + ? abort(403, 'User disabled.') + : Redirect::guest(URL::route($redirectToRoute ?: 'verification.notice')); + } + + return $next($request); + } +}