Use a login-like layout for error messages displayed to non-authenticated users

refs #10009
This commit is contained in:
Alexander A. Klimov 2015-09-22 18:21:25 +02:00
parent 426f64e32a
commit 8e29fe92a5
3 changed files with 23 additions and 27 deletions

View File

@ -29,13 +29,16 @@ class ErrorController extends ActionController
*/ */
public function errorAction() public function errorAction()
{ {
$this->view->noAuthPageNotFound = false;
$error = $this->_getParam('error_handler'); $error = $this->_getParam('error_handler');
$exception = $error->exception; $exception = $error->exception;
/** @var \Exception $exception */ /** @var \Exception $exception */
Logger::error($exception); Logger::error($exception);
Logger::error('Stacktrace: %s', $exception->getTraceAsString()); Logger::error('Stacktrace: %s', $exception->getTraceAsString());
if (! ($isAuthenticated = $this->Auth()->isAuthenticated())) {
$this->innerLayout = 'error';
}
switch ($error->type) { switch ($error->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
@ -46,16 +49,13 @@ class ErrorController extends ActionController
$path = array_shift($path); $path = array_shift($path);
$this->getResponse()->setHttpResponseCode(404); $this->getResponse()->setHttpResponseCode(404);
$this->view->message = $this->translate('Page not found.'); $this->view->message = $this->translate('Page not found.');
if ($this->Auth()->isAuthenticated()) { if ($isAuthenticated) {
if ($modules->hasInstalled($path) && ! $modules->hasEnabled($path)) { if ($modules->hasInstalled($path) && ! $modules->hasEnabled($path)) {
$this->view->message .= ' ' . sprintf( $this->view->message .= ' ' . sprintf(
$this->translate('Enabling the "%s" module might help!'), $this->translate('Enabling the "%s" module might help!'),
$path $path
); );
} }
} else {
$this->innerLayout = 'inline';
$this->view->noAuthPageNotFound = true;
} }
break; break;
@ -99,5 +99,6 @@ class ErrorController extends ActionController
} }
$this->view->request = $error->request; $this->view->request = $error->request;
$this->view->hideControls = ! $isAuthenticated;
} }
} }

View File

@ -0,0 +1,8 @@
<div class="logo">
<div class="image">
<img aria-hidden="true" class="fade-in one" src="<?= $this->baseUrl('img/logo_icinga_big.png'); ?>" alt="<?= $this->translate('The Icinga logo'); ?>" >
</div>
</div>
<div class="below-logo">
<?= $this->render('inline.phtml') ?>
</div>

View File

@ -1,25 +1,12 @@
<?php if ($noAuthPageNotFound) { ?> <?php if (! $hideControls) { ?>
<div id="login">
<div class="logo">
<div class="image">
<img aria-hidden="true" class="fade-in one" src="<?= $this->baseUrl('img/logo_icinga_big.png'); ?>" alt="<?= $this->translate('The Icinga logo'); ?>" >
</div>
</div>
<div class="below-logo" data-base-target="layout">
<div class="content">
<p><strong><?= nl2br($this->escape($message)) ?></strong></p>
</div>
</div>
</div>
<?php } else { ?>
<div class="controls"> <div class="controls">
<?= $this->tabs->showOnlyCloseButton() ?> <?= $this->tabs->showOnlyCloseButton() ?>
</div> </div>
<div class="content"> <?php } ?>
<div class="content">
<p><strong><?= nl2br($this->escape($message)) ?></strong></p> <p><strong><?= nl2br($this->escape($message)) ?></strong></p>
<?php if (isset($stackTrace)) : ?> <?php if (isset($stackTrace)) : ?>
<hr /> <hr />
<pre><?= $this->escape($stackTrace) ?></pre> <pre><?= $this->escape($stackTrace) ?></pre>
<?php endif ?> <?php endif ?>
</div> </div>
<?php } ?>