icingaweb2/application/controllers/TwoFactorController.php

61 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2026-04-22 04:19:19 -04:00
<?php
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Icinga\Controllers;
use Icinga\Application\Hook\TwoFactorHook;
use Icinga\Forms\Account\TwoFactorEnrollmentForm;
use ipl\Html\Contract\Form;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\Web\Compat\CompatController;
class TwoFactorController extends CompatController
{
public function configAction(): void
{
$this->getTabs()->activate('two-factor');
$this->addContent(HtmlElement::create('h1', null, Text::create('Two-Factor Authentication')));
$enrolledMethodName = TwoFactorHook::loadEnrolled()?->getName();
$chooseMethodForm = (new TwoFactorEnrollmentForm($enrolledMethodName !== null))
->populate([TwoFactorEnrollmentForm::METHOD => $enrolledMethodName])
2026-04-22 04:19:19 -04:00
->on(Form::ON_SUBMIT, function (TwoFactorEnrollmentForm $form) {
if ($redirectUrl = $form->getRedirectUrl()) {
$this->redirectNow($redirectUrl);
}
})
->handleRequest($this->getServerRequest());
$this->addContent($chooseMethodForm);
}
public function init(): void
{
$this->getTabs()
->add('account', [
'title' => $this->translate('Update your account'),
'label' => $this->translate('My Account'),
'url' => 'account'
])
->add('navigation', [
'title' => $this->translate('List and configure your own navigation items'),
'label' => $this->translate('Navigation'),
'url' => 'navigation'
])
->add('devices', [
'title' => $this->translate('List of devices you are logged in'),
'label' => $this->translate('My Devices'),
'url' => 'my-devices'
])
->add('two-factor', [
'title' => $this->translate('Configure two-factor authentication'),
'label' => $this->translate('Two-Factor Auth'),
2026-04-29 01:38:20 -04:00
'url' => 'two-factor/config'
2026-04-22 04:19:19 -04:00
]);
}
}