3 namespace BookStack\Http\Middleware;
5 use BookStack\Access\LoginService;
6 use BookStack\Access\Mfa\MfaSession;
9 class AuthenticatedOrPendingMfa
11 protected $loginService;
12 protected $mfaSession;
14 public function __construct(LoginService $loginService, MfaSession $mfaSession)
16 $this->loginService = $loginService;
17 $this->mfaSession = $mfaSession;
21 * Handle an incoming request.
23 * @param \Illuminate\Http\Request $request
24 * @param \Closure $next
28 public function handle($request, Closure $next)
30 $user = auth()->user();
31 $loggedIn = $user !== null;
32 $lastAttemptUser = $this->loginService->getLastLoginAttemptUser();
34 if ($loggedIn || ($lastAttemptUser && $this->mfaSession->isPendingMfaSetup($lastAttemptUser))) {
35 return $next($request);
38 return redirect()->to(url('/login'));