]> BookStack Code Mirror - bookstack/blob - app/Http/Middleware/Authenticate.php
Updated views for permissions and added notifications. Fixes #2 and #7
[bookstack] / app / Http / Middleware / Authenticate.php
1 <?php
2
3 namespace Oxbow\Http\Middleware;
4
5 use Closure;
6 use Illuminate\Contracts\Auth\Guard;
7
8 class Authenticate
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     public function __construct(Guard $auth)
23     {
24         $this->auth = $auth;
25     }
26
27     /**
28      * Handle an incoming request.
29      *
30      * @param  \Illuminate\Http\Request  $request
31      * @param  \Closure  $next
32      * @return mixed
33      */
34     public function handle($request, Closure $next)
35     {
36         if ($this->auth->guest()) {
37             if ($request->ajax()) {
38                 return response('Unauthorized.', 401);
39             } else {
40                 return redirect()->guest('/login');
41             }
42         }
43
44         return $next($request);
45     }
46 }