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