diff --git a/app/modules/web/Controllers/ControllerBase.php b/app/modules/web/Controllers/ControllerBase.php index 49a87284..b25075fa 100644 --- a/app/modules/web/Controllers/ControllerBase.php +++ b/app/modules/web/Controllers/ControllerBase.php @@ -36,7 +36,6 @@ use SP\Core\Context\ContextInterface; use SP\Core\Context\SessionContext; use SP\Core\Events\EventDispatcher; use SP\Core\Exceptions\FileNotFoundException; -use SP\Core\Language; use SP\Core\UI\Theme; use SP\DataModel\ProfileData; use SP\Modules\Web\Controllers\Helpers\LayoutHelper; @@ -91,10 +90,6 @@ abstract class ControllerBase * @var EventDispatcher */ protected $eventDispatcher; - /** - * @var bool - */ - protected $loggedIn = false; /** * @var ConfigData */ @@ -163,8 +158,6 @@ abstract class ControllerBase $this->setViewVars(); } - $this->view->assign('language', substr(Language::$globalLang, 0, 2)); - if (method_exists($this, 'initialize')) { $this->initialize(); } diff --git a/app/modules/web/Controllers/ErrorController.php b/app/modules/web/Controllers/ErrorController.php index a9bda0d9..7fd26f6d 100644 --- a/app/modules/web/Controllers/ErrorController.php +++ b/app/modules/web/Controllers/ErrorController.php @@ -2,8 +2,8 @@ /** * sysPass * - * @author nuxsmin - * @link https://syspass.org + * @author nuxsmin + * @link https://syspass.org * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. @@ -24,11 +24,12 @@ namespace SP\Modules\Web\Controllers; +use DI\Container; use Klein\Klein; -use SP\Bootstrap; +use SP\Core\Exceptions\FileNotFoundException; +use SP\Core\Exceptions\SPException; +use SP\Modules\Web\Controllers\Helpers\LayoutHelper; use SP\Mvc\View\Template; -use SP\Services\Install\Installer; -use SP\Util\Util; /** * Class ErrorController @@ -45,36 +46,83 @@ class ErrorController * @var Klein */ protected $router; + /** + * @var LayoutHelper + */ + protected $layoutHelper; /** * ErrorController constructor. - * @param Template $view - * @param Klein $router + * + * @param Container $container + * @param string $actionName + * @throws \DI\DependencyException + * @throws \DI\NotFoundException */ - public function __construct(Template $view, Klein $router) + public function __construct(Container $container, $actionName) { - $this->view = $view; - $this->router = $router; + $this->view = $container->get(Template::class); + $this->view->setBase('error'); + + $this->router = $container->get(Klein::class); + $this->layoutHelper = $container->get(LayoutHelper::class); + $this->layoutHelper->getPublicLayout('error'); } /** - * @todo + * indexAction */ public function indexAction() { - $this->view->assign('startTime', microtime()); + $this->layoutHelper->getPublicLayout('error'); + $this->view(); + } - $this->view->assign('appInfo', Util::getAppInfo()); - $this->view->assign('appVersion', Installer::VERSION_TEXT); - $this->view->assign('logoIcon', Bootstrap::$WEBURI . '/public/images/logo_icon.png'); - $this->view->assign('logoNoText', Bootstrap::$WEBURI . '/public/images/logo_icon.svg'); - $this->view->assign('logo', Bootstrap::$WEBURI . '/public/images/logo_full_bg.png'); - $this->view->assign('logonobg', Bootstrap::$WEBURI . '/public/images/logo_full_nobg.png'); - $this->view->assign('lang', 'en'); - $this->view->assign('error', 'Error!'); + /** + * Mostrar los datos de la plantilla + */ + protected function view() + { + try { + echo $this->view->render(); + } catch (FileNotFoundException $e) { + processException($e); - $this->router->response()->header('Content-Type', 'text/html; charset=UTF-8'); - $this->router->response()->header('Cache-Control', 'public, no-cache, max-age=0, must-revalidate'); - $this->router->response()->header('Pragma', 'public; max-age=0'); + echo __($e->getMessage()); + } + + die(); + } + + /** + * databaseErrorAction + */ + public function maintenanceErrorAction() + { + $this->layoutHelper->getPublicLayout('error-maintenance'); + + $this->view->append('errors', [ + 'type' => SPException::WARNING, + 'description' => __('Aplicación en mantenimiento'), + 'hint' => __('En breve estará operativa') + ]); + + $this->view(); + } + + /** + * databaseErrorAction + */ + public function databaseErrorAction() + { + $this->layoutHelper->getPublicLayout('error-database'); + + $this->view->append('errors', [ + 'type' => SPException::CRITICAL, + 'description' => __('Error en la verificación de la base de datos'), + 'hint' => __('Consulte con el administrador') + ]); + + $this->view(); } } \ No newline at end of file diff --git a/app/modules/web/Controllers/Helpers/LayoutHelper.php b/app/modules/web/Controllers/Helpers/LayoutHelper.php index 584fd682..4c972b7c 100644 --- a/app/modules/web/Controllers/Helpers/LayoutHelper.php +++ b/app/modules/web/Controllers/Helpers/LayoutHelper.php @@ -112,7 +112,7 @@ class LayoutHelper extends HelperBase $this->loggedIn = $this->context->isLoggedIn(); $this->view->assign('loggedIn', $this->loggedIn); - $this->view->assign('lang', $this->loggedIn ? Language::$userLang : Language::$globalLang); + $this->view->assign('lang', $this->loggedIn ? Language::$userLang : substr(Language::$globalLang, 0, 2)); $this->view->assign('loadApp', $this->context->getAuthCompleted()); @@ -340,23 +340,6 @@ class LayoutHelper extends HelperBase return $this; } - /** - * Sets a full layout page - * - * @param string $page Page/view name - * @return LayoutHelper - */ - public function getErrorLayout($page = '') - { - $this->view->addTemplate('error', '_layouts'); - $this->view->assign('useFixedHeader'); - - $this->setPage($page); - $this->initBody(); - - return $this; - } - /** * Sets a custom layout page * diff --git a/app/modules/web/Controllers/InstallController.php b/app/modules/web/Controllers/InstallController.php index c6e826e5..865d796d 100644 --- a/app/modules/web/Controllers/InstallController.php +++ b/app/modules/web/Controllers/InstallController.php @@ -119,7 +119,7 @@ class InstallController extends ControllerBase try { $this->dic->get(Installer::class)->run($installData); - $this->returnJsonResponse(JsonResponse::JSON_SUCCESS_STICKY, __u('Instalación finalizada')); + $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Instalación finalizada')); } catch (\Exception $e) { processException($e); diff --git a/app/modules/web/Init.php b/app/modules/web/Init.php index 341223b3..0bd05800 100644 --- a/app/modules/web/Init.php +++ b/app/modules/web/Init.php @@ -33,7 +33,6 @@ use SP\Core\Context\SessionContext; use SP\Core\Crypt\CryptSessionHandler; use SP\Core\Crypt\SecureKeyCookie; use SP\Core\Crypt\Session as CryptSession; -use SP\Core\Exceptions\InitializationException; use SP\Core\Language; use SP\Core\ModuleBase; use SP\Core\UI\Theme; @@ -57,7 +56,7 @@ class Init extends ModuleBase * List of controllers that don't need to perform fully initialization * like: install/database checks, session/event handlers initialization */ - const PARTIAL_INIT = ['resource', 'install', 'bootstrap', 'status', 'upgrade']; + const PARTIAL_INIT = ['resource', 'install', 'bootstrap', 'status', 'upgrade', 'error']; /** * @var SessionContext @@ -92,7 +91,6 @@ class Init extends ModuleBase * Initialize Web App * * @param string $controller - * @throws InitializationException * @throws \DI\DependencyException * @throws \DI\NotFoundException * @throws \SP\Core\Exceptions\SPException @@ -144,19 +142,17 @@ class Init extends ModuleBase } // Checks if maintenance mode is turned on - $this->checkMaintenanceMode($this->context); + if ($this->checkMaintenanceMode($this->context)) { + $this->router->response() + ->redirect('index.php?r=error/maintenanceError') + ->send(); + } - try { - // Checks if the database is set up - DBUtil::checkDatabaseExist($this->container->get(Database::class)->getDbHandler(), $this->configData->getDbName()); - } catch (\Exception $e) { - if ($e->getCode() === 1049) { - $this->router->response() - ->redirect('index.php?r=install/index') - ->send(); - } - - throw new InitializationException($e->getMessage()); + // Checks if the database is set up + if (!DBUtil::checkDatabaseExist($this->container->get(Database::class)->getDbHandler(), $this->configData->getDbName())) { + $this->router->response() + ->redirect('index.php?r=error/databaseError') + ->send(); } // Checks if upgrade is needed diff --git a/app/modules/web/themes/material-blue/views/_layouts/error.inc b/app/modules/web/themes/material-blue/views/_layouts/error.inc deleted file mode 100644 index 8610c2fc..00000000 --- a/app/modules/web/themes/material-blue/views/_layouts/error.inc +++ /dev/null @@ -1,47 +0,0 @@ - - - -
-