Show an error message if a ConfigurationError is thrown

This commit is contained in:
Alexander Klimov 2014-07-29 12:25:48 +02:00
parent 4e1e845675
commit e07f2a2b0d

View File

@ -3,7 +3,6 @@
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Web\Controller\BaseConfigController; use Icinga\Web\Controller\BaseConfigController;
use Icinga\Web\Widget\Tab;
use Icinga\Web\Widget\AlertMessageBox; use Icinga\Web\Widget\AlertMessageBox;
use Icinga\Web\Notification; use Icinga\Web\Notification;
use Icinga\Application\Modules\Module; use Icinga\Application\Modules\Module;
@ -12,7 +11,6 @@ use Icinga\Web\Form;
use Icinga\Web\Widget; use Icinga\Web\Widget;
use Icinga\Application\Icinga; use Icinga\Application\Icinga;
use Icinga\Application\Config as IcingaConfig; use Icinga\Application\Config as IcingaConfig;
use Icinga\Data\ResourceFactory;
use Icinga\Form\Config\GeneralForm; use Icinga\Form\Config\GeneralForm;
use Icinga\Form\Config\Authentication\LdapBackendForm; use Icinga\Form\Config\Authentication\LdapBackendForm;
use Icinga\Form\Config\Authentication\DbBackendForm; use Icinga\Form\Config\Authentication\DbBackendForm;
@ -21,6 +19,7 @@ use Icinga\Form\Config\ResourceForm;
use Icinga\Form\Config\LoggingForm; use Icinga\Form\Config\LoggingForm;
use Icinga\Form\Config\ConfirmRemovalForm; use Icinga\Form\Config\ConfirmRemovalForm;
use Icinga\Config\PreservingIniWriter; use Icinga\Config\PreservingIniWriter;
use Icinga\Exception\ConfigurationError;
/** /**
@ -233,6 +232,7 @@ class ConfigController extends BaseConfigController
$backendType = $this->getRequest()->getParam('type'); $backendType = $this->getRequest()->getParam('type');
$authenticationConfig = IcingaConfig::app('authentication')->toArray(); $authenticationConfig = IcingaConfig::app('authentication')->toArray();
try {
switch ($backendType) { switch ($backendType) {
case 'ldap': case 'ldap':
$form = new LdapBackendForm(); $form = new LdapBackendForm();
@ -241,12 +241,12 @@ class ConfigController extends BaseConfigController
$form = new DbBackendForm(); $form = new DbBackendForm();
break; break;
case 'autologin': case 'autologin':
$existing = array_filter($authenticationConfig, function ($e) { return $e['backend'] === 'autologin'; }); foreach ($authenticationConfig as $ac) {
if (false === empty($existing)) { if (array_key_exists('backend', $ac) && $ac['backend'] === 'autologin') {
$this->addErrorMessage( throw new ConfigurationError(
$this->translate('An autologin backend already exists') $this->translate('An autologin backend already exists')
); );
$this->redirectNow('config/configurationerror'); }
} }
$form = new AutologinBackendForm(); $form = new AutologinBackendForm();
break; break;
@ -257,6 +257,10 @@ class ConfigController extends BaseConfigController
)); ));
$this->redirectNow('config/configurationerror'); $this->redirectNow('config/configurationerror');
} }
} catch (ConfigurationError $e) {
$this->addErrorMessage($e->getMessage());
$this->redirectNow('config/configurationerror');
}
$request = $this->getRequest(); $request = $this->getRequest();
if ($request->isPost() && $form->isValid($request->getPost())) { if ($request->isPost() && $form->isValid($request->getPost())) {