mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 07:14:35 +02:00
commit
ecbb0926dc
73
application/controllers/AccountController.php
Normal file
73
application/controllers/AccountController.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
namespace Icinga\Controllers;
|
||||||
|
|
||||||
|
use Icinga\Application\Config;
|
||||||
|
use Icinga\Authentication\User\UserBackend;
|
||||||
|
use Icinga\Data\ConfigObject;
|
||||||
|
use Icinga\Exception\ConfigurationError;
|
||||||
|
use Icinga\Forms\Account\ChangePasswordForm;
|
||||||
|
use Icinga\Forms\PreferenceForm;
|
||||||
|
use Icinga\User\Preferences\PreferencesStore;
|
||||||
|
use Icinga\Web\Controller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* My Account
|
||||||
|
*/
|
||||||
|
class AccountController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@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'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* My account
|
||||||
|
*/
|
||||||
|
public function indexAction()
|
||||||
|
{
|
||||||
|
$config = Config::app()->getSection('global');
|
||||||
|
$user = $this->Auth()->getUser();
|
||||||
|
if ($user->getAdditional('backend_type') === 'db') {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$form = new PreferenceForm();
|
||||||
|
$form->setPreferences($user->getPreferences());
|
||||||
|
if ($config->get('config_backend', 'ini') !== 'none') {
|
||||||
|
$form->setStore(PreferencesStore::create(new ConfigObject(array(
|
||||||
|
'store' => $config->get('config_backend', 'ini'),
|
||||||
|
'resource' => $config->config_resource
|
||||||
|
)), $user));
|
||||||
|
}
|
||||||
|
$form->handleRequest();
|
||||||
|
|
||||||
|
$this->view->form = $form;
|
||||||
|
$this->getTabs()->activate('account');
|
||||||
|
}
|
||||||
|
}
|
@ -128,11 +128,11 @@ class NavigationController extends Controller
|
|||||||
|
|
||||||
$this->getTabs()
|
$this->getTabs()
|
||||||
->add(
|
->add(
|
||||||
'preferences',
|
'account',
|
||||||
array(
|
array(
|
||||||
'title' => $this->translate('Adjust the preferences of Icinga Web 2 according to your needs'),
|
'title' => $this->translate('Update your account'),
|
||||||
'label' => $this->translate('Preferences'),
|
'label' => $this->translate('My Account'),
|
||||||
'url' => 'preference'
|
'url' => 'account'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
->add(
|
->add(
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
<?php
|
|
||||||
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
|
||||||
|
|
||||||
namespace Icinga\Controllers;
|
|
||||||
|
|
||||||
use Icinga\Application\Config;
|
|
||||||
use Icinga\Data\ConfigObject;
|
|
||||||
use Icinga\Forms\PreferenceForm;
|
|
||||||
use Icinga\User\Preferences\PreferencesStore;
|
|
||||||
use Icinga\Web\Controller\BasePreferenceController;
|
|
||||||
use Icinga\Web\Url;
|
|
||||||
use Icinga\Web\Widget\Tab;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Application wide preference controller for user preferences
|
|
||||||
*
|
|
||||||
* @TODO(el): Rename to PreferencesController: https://dev.icinga.org/issues/10014
|
|
||||||
*/
|
|
||||||
class PreferenceController extends BasePreferenceController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Create tabs for this preference controller
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @see BasePreferenceController::createProvidedTabs()
|
|
||||||
*/
|
|
||||||
public static function createProvidedTabs()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
'preferences' => new Tab(array(
|
|
||||||
'title' => t('Adjust the preferences of Icinga Web 2 according to your needs'),
|
|
||||||
'label' => t('Preferences'),
|
|
||||||
'url' => 'preference'
|
|
||||||
)),
|
|
||||||
'navigation' => new Tab(array(
|
|
||||||
'title' => t('List and configure your own navigation items'),
|
|
||||||
'label' => t('Navigation'),
|
|
||||||
'url' => 'navigation'
|
|
||||||
))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show form to adjust user preferences
|
|
||||||
*/
|
|
||||||
public function indexAction()
|
|
||||||
{
|
|
||||||
$config = Config::app()->getSection('global');
|
|
||||||
$user = $this->getRequest()->getUser();
|
|
||||||
|
|
||||||
$form = new PreferenceForm();
|
|
||||||
$form->setPreferences($user->getPreferences());
|
|
||||||
if ($config->get('config_backend', 'ini') !== 'none') {
|
|
||||||
$form->setStore(PreferencesStore::create(new ConfigObject(array(
|
|
||||||
'store' => $config->get('config_backend', 'ini'),
|
|
||||||
'resource' => $config->config_resource
|
|
||||||
)), $user));
|
|
||||||
}
|
|
||||||
$form->handleRequest();
|
|
||||||
|
|
||||||
$this->view->form = $form;
|
|
||||||
$this->getTabs()->activate('preferences');
|
|
||||||
}
|
|
||||||
}
|
|
123
application/forms/Account/ChangePasswordForm.php
Normal file
123
application/forms/Account/ChangePasswordForm.php
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
namespace Icinga\Forms\Account;
|
||||||
|
|
||||||
|
use Icinga\Authentication\User\DbUserBackend;
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
|
use Icinga\User;
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Web\Notification;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form for changing user passwords
|
||||||
|
*/
|
||||||
|
class ChangePasswordForm extends Form
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The user backend
|
||||||
|
*
|
||||||
|
* @var DbUserBackend
|
||||||
|
*/
|
||||||
|
protected $backend;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setSubmitLabel($this->translate('Update Account'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function createElements(array $formData)
|
||||||
|
{
|
||||||
|
$this->addElement(
|
||||||
|
'password',
|
||||||
|
'old_password',
|
||||||
|
array(
|
||||||
|
'label' => $this->translate('Old Password'),
|
||||||
|
'required' => true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->addElement(
|
||||||
|
'password',
|
||||||
|
'new_password',
|
||||||
|
array(
|
||||||
|
'label' => $this->translate('New Password'),
|
||||||
|
'required' => true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->addElement(
|
||||||
|
'password',
|
||||||
|
'new_password_confirmation',
|
||||||
|
array(
|
||||||
|
'label' => $this->translate('Confirm New Password'),
|
||||||
|
'required' => true,
|
||||||
|
'validators' => array(
|
||||||
|
array('identical', false, array('new_password'))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function onSuccess()
|
||||||
|
{
|
||||||
|
$backend = $this->getBackend();
|
||||||
|
$backend->update(
|
||||||
|
$backend->getBaseTable(),
|
||||||
|
array('password' => $this->getElement('new_password')->getValue()),
|
||||||
|
Filter::where('user_name', $this->Auth()->getUser()->getUsername())
|
||||||
|
);
|
||||||
|
Notification::success($this->translate('Account updated'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function isValid($formData)
|
||||||
|
{
|
||||||
|
$valid = parent::isValid($formData);
|
||||||
|
if (! $valid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$oldPasswordEl = $this->getElement('old_password');
|
||||||
|
|
||||||
|
if (! $this->backend->authenticate($this->Auth()->getUser(), $oldPasswordEl->getValue())) {
|
||||||
|
$oldPasswordEl->addError($this->translate('Old password is invalid'));
|
||||||
|
$this->markAsError();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the user backend
|
||||||
|
*
|
||||||
|
* @return DbUserBackend
|
||||||
|
*/
|
||||||
|
public function getBackend()
|
||||||
|
{
|
||||||
|
return $this->backend;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the user backend
|
||||||
|
*
|
||||||
|
* @param DbUserBackend $backend
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setBackend(DbUserBackend $backend)
|
||||||
|
{
|
||||||
|
$this->backend = $backend;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
11
application/views/scripts/account/index.phtml
Normal file
11
application/views/scripts/account/index.phtml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<div class="controls">
|
||||||
|
<?= $tabs ?>
|
||||||
|
</div>
|
||||||
|
<div class="content">
|
||||||
|
<?php if (isset($changePasswordForm)): ?>
|
||||||
|
<h1><?= $this->translate('Account') ?></h1>
|
||||||
|
<?= $changePasswordForm ?>
|
||||||
|
<?php endif ?>
|
||||||
|
<h1><?= $this->translate('Preferences') ?></h1>
|
||||||
|
<?= $form ?>
|
||||||
|
</div>
|
@ -1,6 +0,0 @@
|
|||||||
<div class="controls">
|
|
||||||
<?= $tabs; ?>
|
|
||||||
</div>
|
|
||||||
<div class="content">
|
|
||||||
<?= $form; ?>
|
|
||||||
</div>
|
|
@ -346,10 +346,10 @@ class Web extends EmbeddedWeb
|
|||||||
'icon' => 'user',
|
'icon' => 'user',
|
||||||
'priority' => 900,
|
'priority' => 900,
|
||||||
'children' => array(
|
'children' => array(
|
||||||
'preferences' => array(
|
'account' => array(
|
||||||
'label' => t('Preferences'),
|
'label' => t('My Account'),
|
||||||
'priority' => 100,
|
'priority' => 100,
|
||||||
'url' => 'preference'
|
'url' => 'account'
|
||||||
),
|
),
|
||||||
'logout' => array(
|
'logout' => array(
|
||||||
'label' => t('Logout'),
|
'label' => t('Logout'),
|
||||||
|
@ -118,6 +118,8 @@ class AuthChain implements Authenticatable, Iterator
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($authenticated) {
|
if ($authenticated) {
|
||||||
|
$user->setAdditional('backend_name', $backend->getName());
|
||||||
|
$user->setAdditional('backend_type', $this->config->current()->get('backend'));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user