]> BookStack Code Mirror - bookstack/blob - app/Http/Middleware/Authenticate.php
Started moving MFA and email confirmation to new login flow
[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     /**
11      * Handle an incoming request.
12      */
13     public function handle(Request $request, Closure $next)
14     {
15         if (!hasAppAccess()) {
16             if ($request->ajax()) {
17                 return response('Unauthorized.', 401);
18             } else {
19                 return redirect()->guest(url('/login'));
20             }
21         }
22
23         return $next($request);
24     }
25
26     /**
27      * Provide an error response for when the current user's email is not confirmed
28      * in a system which requires it.
29      */
30     protected function emailConfirmationErrorResponse(Request $request)
31     {
32         if ($request->wantsJson()) {
33             return response()->json([
34                 'error' => [
35                     'code'    => 401,
36                     'message' => trans('errors.email_confirmation_awaiting'),
37                 ],
38             ], 401);
39         }
40
41         if (session()->get('sent-email-confirmation') === true) {
42             return redirect('/register/confirm');
43         }
44
45         return redirect('/register/confirm/awaiting');
46     }
47 }