]> BookStack Code Mirror - bookstack/blob - app/Http/Middleware/RedirectIfAuthenticated.php
6853809ea9d03b5db7a74a817c6f256ef00d832a
[bookstack] / app / Http / Middleware / RedirectIfAuthenticated.php
1 <?php
2
3 namespace BookStack\Http\Middleware;
4
5 use Closure;
6 use Illuminate\Contracts\Auth\Guard;
7
8 class RedirectIfAuthenticated
9 {
10     /**
11      * The Guard implementation.
12      *
13      * @var Guard
14      */
15     protected $auth;
16
17     /**
18      * Create a new filter instance.
19      *
20      * @param Guard $auth
21      *
22      * @return void
23      */
24     public function __construct(Guard $auth)
25     {
26         $this->auth = $auth;
27     }
28
29     /**
30      * Handle an incoming request.
31      *
32      * @param \Illuminate\Http\Request $request
33      * @param \Closure                 $next
34      *
35      * @return mixed
36      */
37     public function handle($request, Closure $next)
38     {
39         $requireConfirmation = setting('registration-confirmation');
40         if ($this->auth->check() && (!$requireConfirmation || ($requireConfirmation && $this->auth->user()->email_confirmed))) {
41             return redirect('/');
42         }
43
44         return $next($request);
45     }
46 }