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
1 changed files with 28 additions and 24 deletions

View File

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