|
3 | 3 |
|
4 | 4 | namespace Icinga\Controllers; |
5 | 5 |
|
| 6 | +use GuzzleHttp\Psr7\ServerRequest; |
| 7 | +use Icinga\Application\ClassLoader; |
6 | 8 | use Icinga\Application\Hook\AuthenticationHook; |
| 9 | +use Icinga\Application\Hook\LoginButton\LoginButton; |
| 10 | +use Icinga\Application\Hook\LoginButtonHook; |
7 | 11 | use Icinga\Application\Icinga; |
8 | 12 | use Icinga\Application\Logger; |
9 | 13 | use Icinga\Common\Database; |
10 | 14 | use Icinga\Exception\AuthenticationException; |
| 15 | +use Icinga\Forms\Authentication\ButtonForm; |
11 | 16 | use Icinga\Forms\Authentication\LoginForm; |
12 | 17 | use Icinga\Web\Controller; |
13 | 18 | use Icinga\Web\Helper\CookieHelper; |
14 | 19 | use Icinga\Web\RememberMe; |
15 | 20 | use Icinga\Web\Url; |
16 | 21 | use RuntimeException; |
| 22 | +use Throwable; |
17 | 23 |
|
18 | 24 | /** |
19 | 25 | * Application wide controller for authentication |
@@ -93,7 +99,33 @@ public function loginAction() |
93 | 99 | } |
94 | 100 | $form->handleRequest(); |
95 | 101 | } |
| 102 | + |
| 103 | + $loginButtons = []; |
| 104 | + $request = ServerRequest::fromGlobals(); |
| 105 | + |
| 106 | + foreach (LoginButtonHook::all() as $class => $hook) { |
| 107 | + try { |
| 108 | + foreach ($hook->getButtons() as $index => $button) { |
| 109 | + assert($button instanceof LoginButton); |
| 110 | + |
| 111 | + $loginButtons[] = (new ButtonForm( |
| 112 | + "$class!$index", |
| 113 | + $button, |
| 114 | + ClassLoader::classBelongsToModule($class) ? ClassLoader::extractModuleName($class) : null |
| 115 | + )) |
| 116 | + ->on(ButtonForm::ON_SUCCESS, function () use ($button): void { |
| 117 | + ($button->onClick)(); |
| 118 | + }) |
| 119 | + ->handleRequest($request); |
| 120 | + } |
| 121 | + } catch (Throwable $e) { |
| 122 | + Logger::error('Failed to execute login button hook: %s', $e); |
| 123 | + continue; |
| 124 | + } |
| 125 | + } |
| 126 | + |
96 | 127 | $this->view->form = $form; |
| 128 | + $this->view->loginButtons = $loginButtons; |
97 | 129 | $this->view->defaultTitle = $this->translate('Icinga Web 2 Login'); |
98 | 130 | $this->view->requiresSetup = $requiresSetup; |
99 | 131 | } |
|
0 commit comments