]> BookStack Code Mirror - bookstack/blob - app/Exceptions/StoppedAuthenticationException.php
Added login redirect system to confirm/mfa
[bookstack] / app / Exceptions / StoppedAuthenticationException.php
1 <?php
2
3 namespace BookStack\Exceptions;
4
5 use BookStack\Auth\Access\LoginService;
6 use BookStack\Auth\User;
7 use Illuminate\Contracts\Support\Responsable;
8
9 class StoppedAuthenticationException extends \Exception implements Responsable
10 {
11
12     protected $user;
13     protected $loginService;
14
15     /**
16      * StoppedAuthenticationException constructor.
17      */
18     public function __construct(User $user, LoginService $loginService)
19     {
20         $this->user = $user;
21         $this->loginService = $loginService;
22         parent::__construct();
23     }
24
25     /**
26      * @inheritdoc
27      */
28     public function toResponse($request)
29     {
30         $redirect = '/login';
31
32         if ($this->loginService->awaitingEmailConfirmation($this->user)) {
33             $redirect = '/register/confirm/awaiting';
34         } else if  ($this->loginService->needsMfaVerification($this->user)) {
35             $redirect = '/mfa/verify';
36         }
37
38         return redirect($redirect);
39     }
40 }