]> BookStack Code Mirror - bookstack/blob - app/Http/Middleware/Authenticate.php
Added initial translation into German (formal)
[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 use BookStack\Exceptions\UserRegistrationException;
8 use Setting;
9
10 class Authenticate
11 {
12     /**
13      * The Guard implementation.
14      * @var Guard
15      */
16     protected $auth;
17
18     /**
19      * Create a new filter instance.
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      * @param  \Illuminate\Http\Request  $request
30      * @param  \Closure  $next
31      * @return mixed
32      */
33     public function handle($request, Closure $next)
34     {
35         if ($this->auth->check() && setting('registration-confirmation') && !$this->auth->user()->email_confirmed) {
36             return redirect(baseUrl('/register/confirm/awaiting'));
37         }
38
39         if ($this->auth->guest() && !setting('app-public')) {
40             if ($request->ajax()) {
41                 return response('Unauthorized.', 401);
42             } else {
43                 return redirect()->guest(baseUrl('/login'));
44             }
45         }
46
47         return $next($request);
48     }
49 }