2016-07-21 06:31:10 -04:00
|
|
|
<?php
|
2026-03-26 12:46:27 -04:00
|
|
|
|
|
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2016-07-21 06:31:10 -04:00
|
|
|
|
|
|
|
|
namespace Icinga\Controllers;
|
|
|
|
|
|
2025-11-21 05:47:56 -05:00
|
|
|
use GuzzleHttp\Psr7\ServerRequest;
|
2016-07-21 06:31:10 -04:00
|
|
|
use Icinga\Application\Config;
|
2026-04-21 06:38:19 -04:00
|
|
|
use Icinga\Application\Hook\TwoFactorHook;
|
2025-11-20 04:07:27 -05:00
|
|
|
use Icinga\Authentication\TwoFactorTotp;
|
2016-07-21 11:38:19 -04:00
|
|
|
use Icinga\Authentication\User\UserBackend;
|
2025-09-30 06:18:26 -04:00
|
|
|
use Icinga\Common\Database;
|
2016-07-21 06:31:10 -04:00
|
|
|
use Icinga\Data\ConfigObject;
|
2016-07-21 11:38:19 -04:00
|
|
|
use Icinga\Exception\ConfigurationError;
|
|
|
|
|
use Icinga\Forms\Account\ChangePasswordForm;
|
2025-11-20 04:07:27 -05:00
|
|
|
use Icinga\Forms\Account\TwoFactorConfigForm;
|
2026-04-21 06:38:19 -04:00
|
|
|
use Icinga\Forms\Account\TwoFactorChooseMethodForm;
|
2016-07-21 06:31:10 -04:00
|
|
|
use Icinga\Forms\PreferenceForm;
|
|
|
|
|
use Icinga\User\Preferences\PreferencesStore;
|
|
|
|
|
use Icinga\Web\Controller;
|
2025-11-21 05:47:56 -05:00
|
|
|
use ipl\Html\Contract\Form;
|
2016-07-21 06:31:10 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* My Account
|
|
|
|
|
*/
|
|
|
|
|
class AccountController extends Controller
|
|
|
|
|
{
|
2025-09-30 06:18:26 -04:00
|
|
|
use Database;
|
|
|
|
|
|
2016-07-21 06:31:10 -04:00
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
public function init()
|
|
|
|
|
{
|
|
|
|
|
$this->getTabs()
|
|
|
|
|
->add('account', array(
|
|
|
|
|
'title' => $this->translate('Update your account'),
|
|
|
|
|
'label' => $this->translate('My Account'),
|
|
|
|
|
'url' => 'account'
|
|
|
|
|
))
|
|
|
|
|
->add('navigation', array(
|
|
|
|
|
'title' => $this->translate('List and configure your own navigation items'),
|
|
|
|
|
'label' => $this->translate('Navigation'),
|
|
|
|
|
'url' => 'navigation'
|
2021-05-21 09:43:06 -04:00
|
|
|
))
|
|
|
|
|
->add(
|
|
|
|
|
'devices',
|
|
|
|
|
array(
|
|
|
|
|
'title' => $this->translate('List of devices you are logged in'),
|
|
|
|
|
'label' => $this->translate('My Devices'),
|
|
|
|
|
'url' => 'my-devices'
|
|
|
|
|
)
|
|
|
|
|
);
|
2016-07-21 06:31:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* My account
|
|
|
|
|
*/
|
|
|
|
|
public function indexAction()
|
|
|
|
|
{
|
|
|
|
|
$config = Config::app()->getSection('global');
|
|
|
|
|
$user = $this->Auth()->getUser();
|
2016-07-21 11:38:19 -04:00
|
|
|
if ($user->getAdditional('backend_type') === 'db') {
|
2021-02-18 02:52:57 -05:00
|
|
|
if ($user->can('user/password-change')) {
|
2019-12-05 03:13:34 -05:00
|
|
|
try {
|
|
|
|
|
$userBackend = UserBackend::create($user->getAdditional('backend_name'));
|
|
|
|
|
} catch (ConfigurationError $e) {
|
|
|
|
|
$userBackend = null;
|
|
|
|
|
}
|
|
|
|
|
if ($userBackend !== null) {
|
|
|
|
|
$changePasswordForm = new ChangePasswordForm();
|
|
|
|
|
$changePasswordForm
|
|
|
|
|
->setBackend($userBackend)
|
|
|
|
|
->handleRequest();
|
|
|
|
|
$this->view->changePasswordForm = $changePasswordForm;
|
|
|
|
|
}
|
2016-07-21 11:38:19 -04:00
|
|
|
}
|
|
|
|
|
}
|
2016-07-21 06:31:10 -04:00
|
|
|
|
2026-04-21 06:38:19 -04:00
|
|
|
// #################################################################################### TODO remove this comment
|
|
|
|
|
|
|
|
|
|
$twoFactorChooseMethodForm = new TwoFactorChooseMethodForm();
|
|
|
|
|
$twoFactorChooseMethodForm->handleRequest(ServerRequest::fromGlobals());
|
|
|
|
|
$this->view->twoFactorForm = $twoFactorChooseMethodForm;
|
2025-12-11 05:49:19 -05:00
|
|
|
|
2026-04-21 06:38:19 -04:00
|
|
|
if (false) {
|
|
|
|
|
$twoFactor = TwoFactorTotp::loadFromDb($this->getDb(), $user->getUsername());
|
|
|
|
|
if ($twoFactor === null) {
|
|
|
|
|
$twoFactor = TwoFactorTotp::generate($user->getUsername());
|
2025-07-24 15:09:08 -04:00
|
|
|
}
|
|
|
|
|
|
2025-11-21 05:47:56 -05:00
|
|
|
|
2026-04-21 06:38:19 -04:00
|
|
|
$twoFactorForm = new TwoFactorConfigForm();
|
|
|
|
|
$twoFactorForm->setUser($user);
|
|
|
|
|
$twoFactorForm->setTwoFactor($twoFactor);
|
|
|
|
|
$twoFactorForm->on(Form::ON_SUBMIT, function (TwoFactorConfigForm $form) {
|
|
|
|
|
if ($redirectUrl = $form->getRedirectUrl()) {
|
|
|
|
|
$this->redirectNow($redirectUrl);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$twoFactorForm->handleRequest(ServerRequest::fromGlobals());
|
|
|
|
|
|
|
|
|
|
$this->view->twoFactorForm = $twoFactorForm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// #################################################################################### TODO remove this comment
|
2025-07-24 15:09:08 -04:00
|
|
|
|
2016-07-21 06:31:10 -04:00
|
|
|
$form = new PreferenceForm();
|
|
|
|
|
$form->setPreferences($user->getPreferences());
|
2022-05-03 04:16:27 -04:00
|
|
|
if (isset($config->config_resource)) {
|
2016-07-21 06:31:10 -04:00
|
|
|
$form->setStore(PreferencesStore::create(new ConfigObject(array(
|
|
|
|
|
'resource' => $config->config_resource
|
|
|
|
|
)), $user));
|
|
|
|
|
}
|
|
|
|
|
$form->handleRequest();
|
|
|
|
|
|
|
|
|
|
$this->view->form = $form;
|
2019-07-12 04:22:01 -04:00
|
|
|
$this->view->title = $this->translate('My Account');
|
2016-07-21 06:31:10 -04:00
|
|
|
$this->getTabs()->activate('account');
|
|
|
|
|
}
|
|
|
|
|
}
|