Пример #1
0
 /**
  * Execute before the router so we can determine if this is a provate controller, and must be authenticated, or a
  * public controller that is open to all.
  *
  * @param Dispatcher $dispatcher
  * @return boolean
  */
 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $controllerName = $dispatcher->getControllerName();
     // Only check permissions on private controllers
     if ($this->acl->isPrivate($controllerName)) {
         // Get the current identity
         $identity = $this->auth->getIdentity();
         // If there is no identity available the user is redirected to index/index
         if (!is_array($identity)) {
             $this->flash->notice('You don\'t have access to this module: private');
             $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
             return false;
         }
         // Check if the user have permission to the current option
         $actionName = $dispatcher->getActionName();
         if (!$this->acl->isAllowed($identity['profile'], $controllerName, $actionName)) {
             $this->flash->notice('You don\'t have access to this module: ' . $controllerName . ':' . $actionName);
             if ($this->acl->isAllowed($identity['profile'], $controllerName, 'index')) {
                 $dispatcher->forward(array('controller' => $controllerName, 'action' => 'index'));
             } else {
                 $dispatcher->forward(array('controller' => 'user_control', 'action' => 'index'));
             }
             return false;
         }
     }
 }
Пример #2
0
 /**
  * Execute before the router so we can determine if this is a private controller, and must be authenticated, or a
  * public controller that is open to all.
  *
  * @param Dispatcher $dispatcher
  * @return boolean
  */
 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $controllerName = $dispatcher->getControllerName();
     // this is not namespaced
     $controllerName = $dispatcher->getHandlerClass();
     // this IS namespaced
     // Only check permissions on private controllers
     // By virtue of extending BaseAuth, this is a private controller
     // Get the current identity
     $identity = $this->auth->getIdentity();
     // If there is no identity available the user is redirected to index/index
     if (!is_array($identity)) {
         $this->flashSession->warning('Please sign in.');
         $dispatcher->forward(array('controller' => 'session', 'action' => 'login'));
         return false;
     }
     //$this->flash->notice( \Dsc\Lib\Debug::dump( $identity ) );
     // Check if the user have permission to the current option
     $actionName = $dispatcher->getActionName();
     if (!$this->acl->isAllowed($identity['profile'], $controllerName, $actionName)) {
         $this->flash->warning('You don\'t have access to: ' . $controllerName . ' : ' . $actionName);
         if ($this->acl->isAllowed($identity['profile'], $controllerName, 'index')) {
             $dispatcher->forward(array('controller' => $controllerName, 'action' => 'index'));
         } else {
             $dispatcher->forward(array('controller' => 'User_Control', 'action' => 'index'));
         }
         return false;
     }
 }
Пример #3
0
 public function __construct(Dispatcher $dispatcher, $exception)
 {
     if ($exception instanceof DispatchException) {
         $dispatcher->forward(array('module' => 'index', 'controller' => 'error', 'action' => 'error404'));
         return false;
     }
     $dispatcher->forward(array('module' => 'index', 'controller' => 'error', 'action' => 'error503'));
     return false;
 }
Пример #4
0
 public function beforeException(Event $event, Dispatcher $dispatcher, $exception)
 {
     //Handle 404 exceptions
     if ($exception instanceof DispatchException) {
         $dispatcher->forward(array('controller' => 'index', 'action' => 'show404'));
         return false;
     }
     //Handle other exceptions
     $dispatcher->forward(array('controller' => 'index', 'action' => 'show503'));
     return false;
 }
Пример #5
0
 public function beforeException(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher, \Phalcon\Exception $exception)
 {
     switch ($exception->getCode()) {
         case $dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
         case $dispatcher::EXCEPTION_ACTION_NOT_FOUND:
             $dispatcher->forward(array('controller' => 'error', 'action' => 'notFound'));
             return false;
         default:
             $dispatcher->forward(array('controller' => 'error', 'action' => 'uncaughtException'));
             return false;
     }
 }
Пример #6
0
 /**
  * This action is executed before execute any action in the application
  *
  * @param Event $event
  * @param Dispatcher $dispatcher
  */
 public function beforeException(Event $event, MvcDispatcher $dispatcher, Exception $exception)
 {
     if ($exception instanceof DispatcherException) {
         switch ($exception->getCode()) {
             case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
             case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                 $dispatcher->forward(array('controller' => 'errors', 'action' => 'show404'));
                 return false;
         }
     }
     $dispatcher->forward(array('controller' => 'errors', 'action' => 'show500'));
     return false;
 }
 /**
  * This action is executed before execute any action in the application
  *
  * @param Event $event
  * @param MvcDispatcher $dispatcher
  * @param Exception $exception
  * @return boolean
  */
 public function beforeException(Event $event, MvcDispatcher $dispatcher, DispatcherException $exception)
 {
     error_log($exception->getMessage() . PHP_EOL . $exception->getTraceAsString());
     if ($exception instanceof DispatcherException) {
         switch ($exception->getCode()) {
             case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
             case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                 $dispatcher->forward(array('controller' => 'error', 'action' => 'error404'));
                 return false;
         }
     }
     $dispatcher->forward(array('controller' => 'errors', 'action' => 'show500'));
     return false;
 }
Пример #8
0
 /**
  * This action is executed before execute any action in the application
  *
  * @param Event               $event
  * @param Dispatcher          $dispatcher
  * @param DispatcherException $exception
  */
 public function beforeException(Event $event, MvcDispatcher $dispatcher, $exception)
 {
     $object = $event->getData();
     $this->view->setVar('message', $object->getMessage());
     switch ($exception->getCode()) {
         case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
         case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
             $dispatcher->forward(array('controller' => 'error', 'action' => 'show404'));
             return false;
         case Dispatcher::EXCEPTION_CYCLIC_ROUTING:
             $dispatcher->forward(['controller' => 'errors', 'action' => 'reports']);
             return false;
     }
 }
Пример #9
0
    public function beforeDispatch(Event $event, Dispatcher $dispatcher)
    {
        $di = PhDi::getDefault();
        // global config
        $config = $di['config'];
        // Take the active controller/action from the dispatcher
        $controller = $dispatcher->getControllerName();
        $action = $dispatcher->getActionName();
        // No ACL checks for AccessController
        if ($controller == 'access') {
            return true;
        }
        // Check whether the "auth" variable exists in session to define the active role
        $auth = $this->session->get('auth');
        if (!$auth) {
            // user not logged in
            $dispatcher->forward(array('controller' => 'access', 'action' => 'signin'));
            return false;
        } else {
            $role = $auth['role'];
        }
        // Check whether acl data already exist
        $aclFileName = $config->application['securityDir'] . "acl.data";
        if (!is_file($aclFileName)) {
            // Obtain the ACL list
            $acl = $this->getAcl();
            // Store serialized list into plain file
            file_put_contents($aclFileName, serialize($acl));
        } else {
            //Restore acl object from serialized file
            $acl = unserialize(file_get_contents($aclFileName));
        }
        // Check if the Role have access to the controller (resource)
        $allowed = $acl->isAllowed($role, $controller, $action);
        if ($allowed != Acl::ALLOW) {
            // If user doesn't have access forward to the index controller
            $flashMessage = <<<EOT
<div class="alert alert-block alert-danger">
    <a class="close" data-dismiss="alert" href="#">×</a>
    <h4 class="alert-heading">Error!</h4>
    You don't have access to this module.
</div>
EOT;
            $this->flashSession->warning($flashMessage);
            $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
            // Returning "false" will tell to the dispatcher to stop the current operation
            return false;
        }
    }
 public function beforeException(Event $event, MvcDispatcher $dispatcher, Exception $exception)
 {
     if ($exception instanceof DispatcherException) {
         switch ($exception->getCode()) {
             //en caso de que el servicio llamado no sea encontrado o la acción no se encuentre
             case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
             case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND:
                 //con dispatcher->forward le decimos que muestre el contenido de la acción show404 del controlador error, a crearlo
                 $dispatcher->forward(array('controller' => 'error', 'action' => 'show404'));
                 return false;
         }
     }
     $dispatcher->forward(array('controller' => 'error', 'action' => 'show500'));
     return false;
 }
Пример #11
0
 public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
 {
     $auth = $this->session->get('auth');
     if (!$auth) {
         $role = 'INVITADO';
     } else {
         $role = $auth["rol_nombre"];
     }
     //nombre del controlador al que intentamos acceder
     $controller = $dispatcher->getControllerName();
     //nombre de la acción a la que intentamos acceder
     $action = $dispatcher->getActionName();
     //obtenemos la Lista de Control de Acceso(acl) que hemos creado
     $acl = $this->getAcl();
     //boolean(true | false) si tenemos permisos devuelve true en otro caso false
     $allowed = $acl->isAllowed($role, $controller, $action);
     //si el usuario no tiene acceso a la zona que intenta acceder
     //se lo redirecciona a login. (o habria que enviarlo al index? )
     //con un mensaje flash
     if ($allowed != \Phalcon\Acl::ALLOW) {
         $this->flash->error("<p>ZONA RESTRINGIDA, NO TIENES PERMISO PARA ACCEDER A LA SECCIÓN SOLICITADA</p>");
         $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
         return false;
     }
 }
Пример #12
0
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     //check whether the 'auth' variable exists in session (if logged in)
     $auth = $this->session->get('auth');
     if ($auth) {
         //logged in
         $role = 'Users';
     } else {
         //not logged in
         $role = 'Guests';
     }
     //take the active controller/action from the dispatcher
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     //obtain the ACL list
     $acl = $this->getAcl(false);
     //check if the role has access to the controller (resource)
     $allowed = $acl->isAllowed($role, $controller, $action);
     if ($allowed != Acl::ALLOW) {
         //does not have access to the controller, fwd to index
         $this->flashSession->error("{$role} don't have access to this page!");
         $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
         //return false to tell dispatcher to stop current operation
         return false;
     } else {
         //user is allowed in (do nothing)
         if ($controller == 'admin' && $action == 'updateAcl') {
             //update acl
             $acl = $this->getAcl(true);
         }
     }
 }
Пример #13
0
 /**
  * @param Dispatcher $dispatcher
  */
 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $controllerName = $dispatcher->getControllerName();
     $actionName = $dispatcher->getActionName();
     // This confirm a private zone
     //check for a closed controller and Action is exist a current session
     if ($this->acl->isClosed($controllerName, $actionName)) {
         if (!is_null($this->auth->getAccess())) {
             //This redirect to another Controller/Action
             $this->response->redirect('dashboard');
             // Disable the view to avoid rendering
             $this->view->disable();
         }
         return true;
     }
     if ($this->acl->isPrivate($controllerName)) {
         if (!is_null($this->auth->getAccess())) {
             //echo "Logeado";
         } else {
             //Display a error by a flash component
             $this->flash->notice('Upss! Access denied, Please Registry first or Login into Kangoo');
             //Execute the dispatcher to move above the user
             $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
             return false;
         }
     }
 }
Пример #14
0
 /**
  * This action is executed before execute any action in the application
  */
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     if ($this->config->application->user_login_form_cookies) {
         //use cookies
         $auth = $this->_getCookie('auth');
         if (!$auth) {
             $role = 'Guests';
         } else {
             $role = $this->_getCookie('role');
             $role = 'Person';
         }
     } else {
         $auth = $this->session->get('auth');
         $auth = $this->_getCookie('auth');
         if (!$auth) {
             $role = 'Guests';
         } else {
             $role = $auth['role'];
             // $role='Common';
         }
     }
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     $acl = $this->getAcl();
     $allowed = $acl->isAllowed($role, $controller, $action);
     if ($allowed != Acl::ALLOW) {
         $this->flash->error("You don't have access to this module");
         $dispatcher->forward(array('controller' => 'user', 'action' => 'login'));
         return false;
     }
 }
Пример #15
0
 /**
  * @param Dispatcher $dispatcher
  *
  * @return bool
  */
 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $returnVal = true;
     $lang = $this->getUriParameter('language');
     $controllerName = $dispatcher->getControllerName();
     if ('1' != $this->config->application->debug) {
         $lang = $this->getUriParameter('language');
         $lang = $lang ? $lang : 'en';
         $key = preg_replace('/[^a-zA-Z0-9\\_]/', '', $lang . '-' . $dispatcher->getControllerName() . '-' . $dispatcher->getActionName() . '-' . implode('-', $dispatcher->getParams()));
         $this->view->cache(array('key' => $key));
         if ($this->view->getCache()->exists($key)) {
             $returnVal = false;
         }
     }
     $auth = $this->session->get('auth');
     $identity = $this->auth->getIdentity();
     if (!$auth) {
         $role = 'Guests';
     } else {
         $role = $identity['profile'];
     }
     // Check if the user have permission to the current option
     $actionName = $dispatcher->getActionName();
     if (!$this->acl->isAllowed($role, $controllerName, $actionName)) {
         $this->flash->notice('You don\'t have access to this module: ' . $controllerName . ':' . $actionName);
         if ($this->acl->isAllowed($identity['profile'], $controllerName, 'index')) {
             $dispatcher->forward(array('controller' => $controllerName, 'action' => 'index'));
         }
         $returnVal = false;
     } else {
         $this->requestInitialize($controllerName);
     }
     return $returnVal;
 }
Пример #16
0
 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $actionName = $dispatcher->getActionName();
     $controllerName = $dispatcher->getControllerName() . 'Controller';
     $nameSpaceName = $dispatcher->getNamespaceName();
     $className = $nameSpaceName . '\\' . ucwords($controllerName);
     $no_auth_array = [];
     if (class_exists($className)) {
         $no_auth_array = array_merge($className::$no_auth_array, self::$no_auth_array);
     }
     if (in_array($actionName, $no_auth_array)) {
         return true;
     }
     if ($this->isLogin()) {
         //判断是否有权限操作此资源
         if (!$this->isAllowed($actionName)) {
             //echo '没有权限';
             $dispatcher->forward(array('controller' => 'index', 'action' => 'noauth'));
             //die();
             return false;
         }
         return true;
     } else {
         if (!($host = $this->request->getServerName())) {
             $host = $this->request->getHttpHost();
         }
         $sourceUrl = $this->request->getScheme() . '://' . $host . $this->request->getURI();
         $url = $this->request->getScheme() . '://' . $host . self::USER_LOGIN_URL . '?ref=' . $sourceUrl;
         $this->redirect($url);
     }
 }
Пример #17
0
 public function beforeException(Event $event, Dispatcher $dispatcher, \Exception $e)
 {
     $this->getLogger()->exception($e);
     $this->response->setStatusCode($e->getCode() ?: 500, $e->getMessage() ?: 'Application error');
     $dispatcher->forward(['namespace' => 'Controller', 'controller' => 'error', 'action' => 'index', 'params' => [0 => $e->getMessage()]]);
     return false;
 }
Пример #18
0
 public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
 {
     // Check whether the "auth" variable exists in session to define the active role
     $auth = $this->session->get('auth');
     if (!$auth) {
         $role = 'Guests';
     } else {
         $role = 'Users';
     }
     // Take the active controller/action from the dispatcher
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     // Obtain the ACL list
     $acl = $this->getAcl();
     // Check if the Role have access to the controller (resource)
     $allowed = $acl->isAllowed($role, $controller, $action);
     if ($allowed != Acl::ALLOW) {
         // If he doesn't have access forward him to the index controller
         $this->flash->error("You don't have access to this module");
         $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
         // Returning "false" we tell to the dispatcher to stop the current operation
         return false;
     }
     //return true;
 }
Пример #19
0
 /**
  * This action is executed before execute any action in the application
  * @param Event $event
  * @param Dispatcher $dispatcher
  */
 public function beforeException(Event $event, MvcDispatcher $dispatcher, Exception $exception)
 {
     if ($exception instanceof DispatcherException) {
         switch ($exception->getCode()) {
             case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
             case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                 $dispatcher->forward(array('controller' => 'errors', 'action' => 'resourceNotFound'));
                 return false;
         }
     }
     $logDir = $this->config->application->logDir;
     $logger = new FileAdapter(APP_PATH . "/{$logDir}/TestZilla.log");
     $logger->log($exception->getMessage(), Logger::ERROR);
     $logger->log($exception->getTraceAsString(), Logger::ERROR);
     $dispatcher->forward(array('controller' => 'errors', 'action' => 'internalServerError'));
     return false;
 }
Пример #20
0
 public function beforeExecuteRoute(\Phalcon\MVC\Dispatcher $dispatcher)
 {
     if ($this->config->auth->enabled) {
         if (!$this->persistent->authenticated && $dispatcher->getActionName() != 'login') {
             $dispatcher->forward(array('action' => 'login'));
         }
     }
 }
Пример #21
0
 public function beforeException(Event $event, Dispatcher $dispatcher)
 {
     global $config;
     if (!$config->setting->sandbox) {
         $dispatcher->forward(['namespace' => 'MyApp\\Controllers', 'controller' => 'public', 'action' => 'show404']);
         return false;
     }
 }
Пример #22
0
 /**
  * @param \Phalcon\Mvc\Dispatcher $dispatcher
  * @return bool
  */
 public function beforeExecuteRoute(\Phalcon\Mvc\Dispatcher $dispatcher)
 {
     $identity = $this->auth->getIdentity();
     if (!is_array($identity) && $dispatcher->getControllerName() != 'user' && ($dispatcher->getActionName() != 'login' || $dispatcher->getActionName() != 'register')) {
         $this->flashSession->notice('Please Login');
         $dispatcher->forward(['controller' => 'user', 'action' => 'login']);
         return false;
     }
 }
Пример #23
0
 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $controllerName = $dispatcher->getControllerName();
     //Only check permissions on private controllers
     if ($this->acl->isPrivate($controllerName)) {
         $this->assets->addCss('css/bootstrap2.css')->addCss('css/bootstrap-responsive2.css')->addCss('css/admin.css');
         //Get the current identity
         $identity = $this->auth->getIdentity();
         //If there is no identity available the user is redirected to index/index
         if (!is_array($identity)) {
             $this->flash->notice('You don\'t have access to this module: private');
             $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
             return false;
         }
         //Check if the user have permission to the current option
         $actionName = $dispatcher->getActionName();
         if (!$this->acl->isAllowed($identity['profile'], $controllerName, $actionName)) {
             $this->flash->notice('You don\'t have access to this module: ' . $controllerName . ':' . $actionName);
             if ($this->acl->isAllowed($identity['profile'], $controllerName, 'index')) {
                 $dispatcher->forward(array('controller' => $controllerName, 'action' => 'index'));
             } else {
                 $dispatcher->forward(array('controller' => 'user_control', 'action' => 'index'));
             }
             return false;
         }
     } else {
         $this->assets->addCss('css/bootstrap.css')->addCss('css/bootstrap-responsive.css')->addCss('css/style.css');
     }
     $this->assets->addCss('//fonts.googleapis.com/css?family=Ubuntu:400,500,700,300italic,400italic,500italic&amp;subset=latin,cyrillic-ext', false)->addCss('//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css', false);
     //adding js
     $this->assets->addJs('//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js', false)->addJs('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js', false)->addJs('//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js', false);
     //set language
     $locality = $this->session->get('language') . '.UTF-8';
     if (defined('LC_MESSAGES')) {
         setlocale(LC_ALL, $locality);
         // Linux
     } else {
         putenv("LC_ALL={$locality}");
         // windows
     }
     bindtextdomain('messages', '../app/lang');
     //Tell the application to use this text domain, or messages.mo.
     textdomain('messages');
 }
Пример #24
0
 /**
  * Registers services related to the module
  *
  * @param DiInterface $dependencyInjector
  */
 public function registerServices(DiInterface $dependencyInjector)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     /**
      * Registering a dispatcher
      */
     $dependencyInjector->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Frontend\\Controllers');
         /**
          * Not-found action or handler
          */
         $eventsManager = new EventsManager();
         $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
             switch ($exception->getCode()) {
                 case Dispatcher::EXCEPTION_CYCLIC_ROUTING:
                 case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                 case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                     $dispatcher->forward(['controller' => 'about', 'action' => 'error']);
                     return false;
             }
         });
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     /**
      * Setting up the view component
      */
     $dependencyInjector->set('view', function () {
         $view = new View();
         $view->registerEngines(array('.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     });
     $dependencyInjector->set('viewCache', function () use($config) {
         //Cache data for one day by default
         $frontCache = new OutputFrontend(array("lifetime" => 86400));
         //File connection settings
         $cache = new FileBackend($frontCache, array('cacheDir' => STATIC_PATH . '/'));
         return $cache;
     });
     $dependencyInjector->set('cookies', function () {
         $cookies = new Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $dependencyInjector->set('db', function () use($config) {
         return new DbAdapter($config->database->toArray());
     });
 }
Пример #25
0
 /**
  * This action is executed before execute any action in the application
  */
 public function beforeDispatch(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher)
 {
     // check installation
     /*if (!$this->_di->get('config')->installed) {
           $this->_di->set('installationRequired', true);
           if ($dispatcher->getControllerName() != 'install') {
               return $dispatcher->forward([
                   'module' => 'core',
                   "controller" => "install",
                   "action" => "index"
               ]);
           }
           return;
       }*/
     $module = $dispatcher->getModuleName();
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     $viewer = $this->_di->get('viewer');
     $acl = $this->_di->get('acl');
     $registry = $this->_di->get('registry');
     $adminModuleName = $registry->adminModule ? $registry->adminModule : 'admin';
     // check admin area
     if ($module == $adminModuleName) {
         if ($controller == 'admin') {
             return;
         }
         if ($acl->isAllowed($viewer->getRole(), \Engine\Acl\Dispatcher::ACL_ADMIN_MODULE, \Engine\Acl\Dispatcher::ACL_ADMIN_CONTROLLER, '*') || $acl->isAllowed($viewer->getRole(), \Engine\Acl\Dispatcher::ACL_ADMIN_MODULE, \Engine\Acl\Dispatcher::ACL_ADMIN_CONTROLLER, 'read')) {
             return;
         }
         if ($acl->isAllowed($viewer->getRole(), $module, $controller, $action, false)) {
             return;
         }
         if ($this->_di->get('request')->isAjax() == true) {
             return $dispatcher->forward(["controller" => 'admin', "action" => 'denied']);
         } else {
             return $dispatcher->forward(["controller" => 'admin', "action" => 'index']);
         }
     } else {
         if (!$acl->isAllowed($viewer->getRole(), $module, $controller, $action, true)) {
             return $dispatcher->forward(["controller" => 'error', "action" => 'show404']);
         }
     }
 }
Пример #26
0
 /**
  * Triggered before the dispatcher throws any exception
  */
 public function beforeException(Event $event, Dispatcher $dispatcher, $exception)
 {
     echo 'testing';
     // Handle 404 exceptions
     if ($exception instanceof DispatchException) {
         $dispatcher->forward(array('controller' => 'quick-response', 'action' => 'sendNotFoundStatus'));
         return false;
     }
     // Alternative way, controller or action doesn't exist
     if ($event->getType() == 'beforeException') {
         switch ($exception->getCode()) {
             case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
             case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                 $dispatcher->forward(array('controller' => 'quick-response', 'action' => 'sendNotFoundStatus'));
                 return false;
         }
     }
     return true;
 }
Пример #27
0
 public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
 {
     $controller = $dispatcher->getControllerName();
     if ($controller == 'rss') {
         return true;
     }
     if (!$this->session->get('auth') && $controller != 'session') {
         $dispatcher->forward(array('controller' => 'session', 'action' => 'index'));
         return false;
     }
 }
Пример #28
0
 public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
 {
     // Is client controller
     if ($dispatcher->getControllerName() == 'client') {
         // has client access
         return;
     }
     if (!$this->session->has('auth')) {
         if ($dispatcher->getControllerName() != 'login') {
             $dispatcher->forward(array('controller' => 'login', 'action' => 'index'));
             return false;
         }
         return;
     } else {
         if ($dispatcher->getControllerName() == 'login') {
             $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
             return false;
         }
     }
 }
Пример #29
0
 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $this->view->setVar('user', $this->user);
     $role = $this->user ? 'user' : 'guest';
     if ($dispatcher->getControllerName() !== 'static') {
         if (!$this->acl->isAllowed($role, $this->router->getControllerName(), $this->router->getActionName())) {
             $dispatcher->forward(['controller' => 'static', 'action' => 'error403']);
             return false;
         }
     }
 }
Пример #30
0
 /**
  * This action is executed before execute any action in the application
  *
  * @param Event $event
  * @param Dispatcher $dispatcher
  *
  * @return boolean success
  */
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     $success = true;
     $acl = $this->getAcl();
     $allowed = $acl->isAllowed($this->session->get('auth') ? 'Users' : 'Guests', $dispatcher->getControllerName(), $dispatcher->getActionName());
     if ($allowed != Acl::ALLOW) {
         $dispatcher->forward(['controller' => 'status', 'action' => 'index', 'params' => [401]]);
         $this->session->destroy();
     }
     return $success;
 }