. */ namespace SP\Modules\Web\Controllers; use Klein\Klein; use Psr\Container\ContainerInterface; use SP\Config\Config; use SP\Core\Acl\Acl; use SP\Core\Acl\UnauthorizedPageException; use SP\Core\Bootstrap\BootstrapBase; use SP\Core\Context\ContextInterface; use SP\Core\Events\EventDispatcher; use SP\Core\Exceptions\SessionTimeout; use SP\Core\Exceptions\SPException; use SP\Core\PhpExtensionChecker; use SP\Core\UI\ThemeInterface; use SP\Http\Request; use SP\Modules\Web\Controllers\Traits\WebControllerTrait; /** * Class SimpleControllerBase * * @package SP\Modules\Web\Controllers */ abstract class SimpleControllerBase { use WebControllerTrait; // TODO: remove when controllers are ready protected ContainerInterface $dic; protected EventDispatcher $eventDispatcher; protected Config $config; protected ContextInterface $session; protected ThemeInterface $theme; protected Klein $router; protected Acl $acl; protected Request $request; protected PhpExtensionChecker $extensionChecker; /** * @throws \SP\Core\Exceptions\SessionTimeout * @throws \JsonException */ public function __construct( EventDispatcher $eventDispatcher, Config $config, ContextInterface $session, ThemeInterface $theme, Klein $router, Acl $acl, Request $request, PhpExtensionChecker $extensionChecker ) { // TODO: remove when controllers are ready $this->dic = BootstrapBase::getContainer(); $this->controllerName = $this->getControllerName(); $this->configData = $config->getConfigData(); $this->eventDispatcher = $eventDispatcher; $this->config = $config; $this->session = $session; $this->theme = $theme; $this->router = $router; $this->acl = $acl; $this->request = $request; $this->extensionChecker = $extensionChecker; $this->setup = true; // TODO: call handleSessionTimeout from controller::initialize directly try { if (method_exists($this, 'initialize')) { $this->initialize(); } } catch (SessionTimeout $sessionTimeout) { $this->handleSessionTimeout( function () { return true; } ); throw $sessionTimeout; } } abstract protected function initialize(): void; /** * Comprobaciones * * @throws SessionTimeout */ protected function checks(): void { if ($this->session->isLoggedIn() === false || $this->session->getAuthCompleted() !== true ) { throw new SessionTimeout(); } // $this->checkSecurityToken($this->session, $this->request); } /** * Comprobar si está permitido el acceso al módulo/página. * * @throws UnauthorizedPageException */ protected function checkAccess(int $action): void { if (!$this->acl->checkUserAccess($action) && !$this->session->getUserData()->getIsAdminApp() ) { throw new UnauthorizedPageException(SPException::INFO); } } }