]> BookStack Code Mirror - bookstack/blob - app/Http/Middleware/Authenticate.php
Improved empty lists. Fixes #10.
[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 use Setting;
8
9 class Authenticate
10 {
11     /**
12      * The Guard implementation.
13      *
14      * @var Guard
15      */
16     protected $auth;
17
18     /**
19      * Create a new filter instance.
20      *
21      * @param  Guard $auth
22      */
23     public function __construct(Guard $auth)
24     {
25         $this->auth = $auth;
26     }
27
28     /**
29      * Handle an incoming request.
30      *
31      * @param  \Illuminate\Http\Request  $request
32      * @param  \Closure  $next
33      * @return mixed
34      */
35     public function handle($request, Closure $next)
36     {
37         $sitePublic = Setting::get('app-public', false) === 'true';
38         if ($this->auth->guest() && !$sitePublic) {
39             if ($request->ajax()) {
40                 return response('Unauthorized.', 401);
41             } else {
42                 return redirect()->guest('/login');
43             }
44         }
45
46         return $next($request);
47     }
48 }