]> BookStack Code Mirror - bookstack/blob - app/Http/Middleware/Authenticate.php
a171a8a2d4c2b9219376d60fa82d2b2a71d48572
[bookstack] / app / Http / Middleware / Authenticate.php
1 <?php
2
3 namespace BookStack\Http\Middleware;
4
5 use Closure;
6 use Illuminate\Http\Request;
7
8 class Authenticate
9 {
10     use ChecksForEmailConfirmation;
11
12     /**
13      * Handle an incoming request.
14      */
15     public function handle(Request $request, Closure $next)
16     {
17         if ($this->awaitingEmailConfirmation()) {
18             return $this->emailConfirmationErrorResponse($request);
19         }
20
21         if (!hasAppAccess()) {
22             if ($request->ajax()) {
23                 return response('Unauthorized.', 401);
24             } else {
25                 return redirect()->guest(url('/login'));
26             }
27         }
28
29         return $next($request);
30     }
31 }