Reduce reliance on CMS module from Backend module

added backend 404 view, fixed return to backend URL in the access denied view on backend only instances
This commit is contained in:
Luke Towers 2019-01-15 11:46:48 -06:00
parent a9a0544ab0
commit d6e680799f
5 changed files with 65 additions and 17 deletions

View File

@ -60,6 +60,21 @@ class BackendController extends ControllerBase
self::extendableExtendCallback($callback); self::extendableExtendCallback($callback);
} }
/**
* Pass unhandled URLs to the CMS Controller, if it exists
*
* @param string $url
* @return Response
*/
protected function passToCmsController($url)
{
if (class_exists('\Cms\Classes\Controller')) {
return App::make('Cms\Classes\Controller')->run($url);
} else {
return Response::make(View::make('backend::404'), 404);
}
}
/** /**
* Finds and serves the requested backend controller. * Finds and serves the requested backend controller.
* If the controller cannot be found, returns the Cms page with the URL /404. * If the controller cannot be found, returns the Cms page with the URL /404.
@ -78,7 +93,7 @@ class BackendController extends ControllerBase
if (!App::hasDatabase()) { if (!App::hasDatabase()) {
return Config::get('app.debug', false) return Config::get('app.debug', false)
? Response::make(View::make('backend::no_database'), 200) ? Response::make(View::make('backend::no_database'), 200)
: App::make('Cms\Classes\Controller')->run($url); : $this->passToCmsController($url);
} }
/* /*
@ -105,7 +120,7 @@ class BackendController extends ControllerBase
$pluginCode = ucfirst($author) . '.' . ucfirst($plugin); $pluginCode = ucfirst($author) . '.' . ucfirst($plugin);
if (PluginManager::instance()->isDisabled($pluginCode)) { if (PluginManager::instance()->isDisabled($pluginCode)) {
return App::make('Cms\Classes\Controller')->setStatusCode(404)->run('/404'); return Response::make(View::make('backend::404'), 404);
} }
$controller = $params[2] ?? 'index'; $controller = $params[2] ?? 'index';
@ -124,7 +139,7 @@ class BackendController extends ControllerBase
/* /*
* Fall back on Cms controller * Fall back on Cms controller
*/ */
return App::make('Cms\Classes\Controller')->run($url); return $this->passToCmsController($url);
} }
/** /**

View File

@ -339,11 +339,15 @@ class Controller extends Extendable
$result = null; $result = null;
if (!$this->actionExists($actionName)) { if (!$this->actionExists($actionName)) {
if (Config::get('app.debug', false)) {
throw new SystemException(sprintf( throw new SystemException(sprintf(
"Action %s is not found in the controller %s", "Action %s is not found in the controller %s",
$actionName, $actionName,
get_class($this) get_class($this)
)); ));
} else {
Response::make(View::make('backend::404'), 404);
}
} }
// Execute the action // Execute the action
@ -396,7 +400,7 @@ class Controller extends Extendable
* Validate the handler name * Validate the handler name
*/ */
if (!preg_match('/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/', $handler)) { if (!preg_match('/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/', $handler)) {
throw new SystemException(Lang::get('cms::lang.ajax_handler.invalid_name', ['name'=>$handler])); throw new SystemException(Lang::get('backend::lang.ajax_handler.invalid_name', ['name'=>$handler]));
} }
/* /*
@ -407,7 +411,7 @@ class Controller extends Extendable
foreach ($partialList as $partial) { foreach ($partialList as $partial) {
if (!preg_match('/^(?!.*\/\/)[a-z0-9\_][a-z0-9\_\-\/]*$/i', $partial)) { if (!preg_match('/^(?!.*\/\/)[a-z0-9\_][a-z0-9\_\-\/]*$/i', $partial)) {
throw new SystemException(Lang::get('cms::lang.partial.invalid_name', ['name'=>$partial])); throw new SystemException(Lang::get('backend::lang.partial.invalid_name', ['name'=>$partial]));
} }
} }
} }
@ -421,7 +425,7 @@ class Controller extends Extendable
* Execute the handler * Execute the handler
*/ */
if (!$result = $this->runAjaxHandler($handler)) { if (!$result = $this->runAjaxHandler($handler)) {
throw new ApplicationException(Lang::get('cms::lang.ajax_handler.not_found', ['name'=>$handler])); throw new ApplicationException(Lang::get('backend::lang.ajax_handler.not_found', ['name'=>$handler]));
} }
/* /*

View File

@ -17,22 +17,32 @@ return [
], ],
'page' => [ 'page' => [
'untitled' => 'Untitled', 'untitled' => 'Untitled',
'404' => [
'label' => 'Page Not Found',
'help' => "We searched and searched but the requested URL just couldn't be found. Perhaps you were looking for something else?",
'back_link' => 'Go back to the previous page',
],
'access_denied' => [ 'access_denied' => [
'label' => 'Access denied', 'label' => 'Access denied',
'help' => "You don't have the required permissions to view this page.", 'help' => "You don't have the required permissions to view this page.",
'cms_link' => 'Return to the back-end' 'cms_link' => 'Return to the back-end',
], ],
'no_database' => [ 'no_database' => [
'label' => 'Database missing', 'label' => 'Database missing',
'help' => "A database is required to access the back-end. Check the database is configured and migrated before trying again.", 'help' => "A database is required to access the back-end. Check the database is configured and migrated before trying again.",
'cms_link' => 'Return to the homepage' 'cms_link' => 'Return to the homepage',
], ],
'invalid_token' => [ 'invalid_token' => [
'label' => 'Invalid security token' 'label' => 'Invalid security token',
] ],
], ],
'partial' => [ 'partial' => [
'not_found_name' => "The partial ':name' is not found." 'not_found_name' => "The partial ':name' is not found.",
'invalid_name' => 'Invalid partial name: :name.',
],
'ajax_handler' => [
'invalid_name' => 'Invalid AJAX handler name: :name.',
'not_found' => "AJAX handler ':name' was not found."
], ],
'account' => [ 'account' => [
'signed_in_as' => 'Signed in as :full_name', 'signed_in_as' => 'Signed in as :full_name',

View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="<?= App::getLocale() ?>">
<head>
<meta charset="utf-8">
<title><?= Lang::get('backend::lang.page.404.label') ?></title>
<link href="<?= Url::to('/modules/system/assets/css/styles.css') ?>" rel="stylesheet">
</head>
<body>
<div class="container">
<h1><i class="icon-chain-broken warning"></i> <?= Lang::get('backend::lang.page.404.label') ?></h1>
<br>
<p class="lead"><?= Lang::get('backend::lang.page.404.help') ?></p>
<p class="lead"><span style="font-family: monospace;"> <?= e(url()->current()); ?></span></p>
<a href="javascript:;" onclick="history.go(-1); return false;"><?= Lang::get('backend::lang.page.404.back_link') ?></a>
<br><br>
<a href="<?= Backend::url('') ?>"><?= Lang::get('backend::lang.page.access_denied.cms_link') ?></a>
</div>
</body>
</html>

View File

@ -9,7 +9,7 @@
<div class="container"> <div class="container">
<h1><i class="icon-lock warning"></i> <?= Lang::get('backend::lang.page.access_denied.label') ?></h1> <h1><i class="icon-lock warning"></i> <?= Lang::get('backend::lang.page.access_denied.label') ?></h1>
<p class="lead"><?= Lang::get('backend::lang.page.access_denied.help') ?></p> <p class="lead"><?= Lang::get('backend::lang.page.access_denied.help') ?></p>
<a href="<?= Backend::url('/') ?>"><?= Lang::get('backend::lang.page.access_denied.cms_link') ?></a> <a href="<?= Backend::url('') ?>"><?= Lang::get('backend::lang.page.access_denied.cms_link') ?></a>
</div> </div>
</body> </body>
</html> </html>