|
8 | 8 | use Icinga\Application\Logger; |
9 | 9 | use Icinga\Common\Database; |
10 | 10 | use Icinga\Exception\AuthenticationException; |
| 11 | +use Icinga\Forms\Authentication\Cancel2FAForm; |
| 12 | +use Icinga\Forms\Authentication\Challenge2FAForm; |
11 | 13 | use Icinga\Forms\Authentication\LoginForm; |
12 | 14 | use Icinga\Web\Controller; |
13 | 15 | use Icinga\Web\Helper\CookieHelper; |
14 | 16 | use Icinga\Web\RememberMe; |
| 17 | +use Icinga\Web\Session; |
15 | 18 | use Icinga\Web\Url; |
16 | 19 | use RuntimeException; |
17 | 20 |
|
@@ -41,7 +44,16 @@ public function loginAction() |
41 | 44 | if (($requiresSetup = $icinga->requiresSetup()) && $icinga->setupTokenExists()) { |
42 | 45 | $this->redirectNow(Url::fromPath('setup')); |
43 | 46 | } |
44 | | - $form = new LoginForm(); |
| 47 | + |
| 48 | + $user = $this->Auth()->getUser(); |
| 49 | + if ($user !== null && $user->getTwoFactorEnabled() |
| 50 | + && Session::getSession()->get('must_challenge_2fa_token', false) === true) { |
| 51 | + $form = new Challenge2FAForm(); |
| 52 | + $cancel2faForm = new Cancel2FAForm(); |
| 53 | + $cancel2faForm->handleRequest(); |
| 54 | + } else { |
| 55 | + $form = new LoginForm(); |
| 56 | + } |
45 | 57 |
|
46 | 58 | if (RememberMe::hasCookie() && $this->hasDb()) { |
47 | 59 | $authenticated = false; |
@@ -91,14 +103,10 @@ public function loginAction() |
91 | 103 | ->sendResponse(); |
92 | 104 | exit; |
93 | 105 | } |
94 | | - // FORM DOES NOT REDIRECT, IF USER HAS 2FA ENABLED and token hasn't been challenged |
95 | 106 | $form->handleRequest(); |
96 | 107 | } |
97 | | -// if ($user->has2FA() && irgendwas_mit_session()) { |
98 | | -// // 2 FA form erstellen und zeigen und handeln |
99 | | - // in der session speichern ob der token gepasst hat |
100 | | -// } |
101 | 108 | $this->view->form = $form; |
| 109 | + $this->view->cancel2faForm = $cancel2faForm ?? null; |
102 | 110 | $this->view->defaultTitle = $this->translate('Icinga Web 2 Login'); |
103 | 111 | $this->view->requiresSetup = $requiresSetup; |
104 | 112 | } |
|
0 commit comments