public function beforeExecuteRoute(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher) { $userEnum = Core_UserCenter_Enum::getInstance(); // Получаем активные контроллер и действие от диспетчера $controller = $dispatcher->getControllerName(); $action = $dispatcher->getActionName(); // Получаем список ACL $acl = $this->_getAcl(); if ($acl->isAllowed($userEnum->getName($userEnum::GUEST), $controller, $action)) { return TRUE; } // Проверяем, установлен ли в сессии user $isAuth = $this->session->has('user'); //Если не авторизован, но перенаправляем на страницу авторизации if (!$isAuth) { return $this->_forwardToLogin(); } $user = $this->session->get('user'); $role = $user->type; // Проверяем, имеет ли данная роль доступ к контроллеру (ресурсу) $allowed = $acl->isAllowed($userEnum->getName($role), $controller, $action); if ($allowed != Phalcon\Acl::ALLOW) { throw new Core_UserCenter_Exception_AccessDenied($controller, $action, $role); } }
public function beforeExecuteRoute(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher) { $authentificationModule = $this->getDI()->get("authentificationModule"); if ($authentificationModule == null) { return; } $controller = $dispatcher->getControllerName(); $action = $dispatcher->getActionName(); error_log("Controleur: {$controller}, Action: {$action}"); if ($controller === "connexion" || $controller === "error") { $config = $this->getDI()->get("config"); $this->getDI()->get("view")->setViewsDir($config->application->services->viewsDir); // }else if($this->estAnonyme()){ // error_log("2"); // return $this->forwardToUnauthorizedPage(); } else { if (!$this->estAuthentifie()) { return $this->forwardToLoginPage(); } else { if (!$this->session->get("info_utilisateur")->estAdmin && !$this->session->get("info_utilisateur")->estPilote) { $this->session->set("erreur", "Droits insuffisants"); return $this->forwardToLoginPage(); } else { // Contrôle d'accès. return $this->filtrerRoutes($controller, $action); } } } }
/** * This action is executed before execute any action in the application */ public function beforeDispatch(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher) { $auth = $this->session->get('auth'); if (!$auth) { $role = 'Guests'; } else { $role = 'Users'; } $controller = $dispatcher->getControllerName(); $action = $dispatcher->getActionName(); $acl = $this->getAcl(); $allowed = $acl->isAllowed($role, $controller, $action); if ($allowed != Phalcon\Acl::ALLOW) { $this->flash->error("You don't have access to this module"); $dispatcher->forward(array('controller' => 'index', 'action' => 'index')); return false; } }
public function beforeExecuteRoute(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher) { // Получаем активные контроллер и действие от диспетчера $controller = $dispatcher->getControllerName(); $action = $dispatcher->getActionName(); // Получаем список ACL $acl = $this->_getAcl(); if ($acl->isAllowed(Core_UserCenter_Enum::GUESTS, $controller, $action)) { return TRUE; } // Проверяем, установлена ли в сессии переменная "auth" для определения активной роли. $auth = $this->session->has('auth_type'); if (!$auth) { return $this->_forwardToLogin(); } $role = $this->session->get('auth_type')['type']; // Проверяем, имеет ли данная роль доступ к контроллеру (ресурсу) $allowed = $acl->isAllowed($role, $controller, $action); if ($allowed != Phalcon\Acl::ALLOW) { throw new Core_UserCenter_Exception_AccessDenied($controller, $action, $role); } }
/** * This action is executed before execute any action in the application */ public function beforeDispatch(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher) { $auth = $this->session->get('auth'); if (!$auth) { $auth['role'] = 'Guest'; $role = 'Guest'; } else { $role = $auth['role']; } $controller = $dispatcher->getControllerName(); $action = $dispatcher->getActionName(); $acl = $this->getAcl(); $allowed = $acl->isAllowed($role, $controller, $action); if ($role == 'Admin' || $role == 'User' || $role == 'Guest') { return true; } elseif ($allowed != Phalcon\Acl::ALLOW) { if ($role != 'Guest') { $this->flash->error("You don't have access to {$controller}/{$action}) please login to get access"); } $dispatcher->forward(array('namespace' => 'PRIME\\Controllers', 'controller' => 'session', 'action' => 'index')); return false; } }
public function beforeException(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher, Exception $e) { $this->_trace[] = 'beforeException'; $this->_test->assertEquals($this->_controllerName, $dispatcher->getControllerName()); $this->_test->assertEquals($this->_actionName, $dispatcher->getActionName()); $this->_test->assertEquals($e->getMessage(), $this->_exceptionMessage); $this->_test->assertEquals(get_class($e), $this->_exceptionType); return false; }
public function beforeExecuteRoute(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher) { $authentificationModule = $this->getDI()->get("authentificationModule"); if ($authentificationModule == null) { return; } $controller = $dispatcher->getControllerName(); $action = $dispatcher->getActionName(); $config = $this->getDI()->get("config"); if ($controller === "connexion" || $controller === "error") { $config = $this->getDI()->get("config"); $this->getDI()->get("view")->setViewsDir($config->application->services->viewsDir); } else { if ($controller === "igo" && ($action === "configuration" || $action === "index")) { $configuration = $this->obtenirConfiguration($action, $dispatcher); if (isset($this->getDi()->getConfig()->configurations[$configuration])) { $file = $this->getDi()->getConfig()->configurations[$configuration]; } else { $file = $this->getDi()->getConfig()->configurationsDir . $configuration . '.xml'; } if (!file_exists($file) && !curl_url_exists($file)) { return $this->forwardToErrorPage(); } if ($this->estAuthentificationRequise($configuration) && !$this->estAnonyme() && !$this->estAuthentifie()) { return $this->forwardToLoginPage(); } else { if ($this->estAuthentificationRequise($configuration) && $this->estRoleSelectionneRequis() && !$this->estRoleSelectionne()) { return $this->forwardToRolePage(); } else { if (!$this->estAuthentificationRequise($configuration) && !$this->estAuthentifie()) { $authentificationModule = $this->getDI()->get("authentificationModule"); if (!$this->session->has("info_utilisateur")) { $this->session->set("info_utilisateur", new SessionController()); } $configuration = $this->getDI()->get("config"); if ($configuration->offsetExists("database")) { // Si la BD n'existe pas dans la config on n'ajoute pas de profil et on se base sur le xml if ($this->estRoleSelectionneRequis()) { $this->session->get("info_utilisateur")->profilActif = IgoProfil::findFirst("nom = '{$configuration->application->authentification->nomProfilAnonyme}'")->id; } else { if (isset($configuration->application->authentification->nomProfilAnonyme)) { $this->session->get("info_utilisateur")->profils = IgoProfil::find("nom = '{$configuration->application->authentification->nomProfilAnonyme}'"); } } } $this->session->get("info_utilisateur")->estAnonyme = true; } else { if ($this->estRoleSelectionneRequis() && !$this->estRoleSelectionne()) { return $this->forwardToRolePage(); } } } } if ($this->estAnonyme() && isset($config->application->authentification->permettreAccesAnonyme) && !$config->application->authentification->permettreAccesAnonyme) { return $this->forwardToUnauthorizedPage(); } } else { if ($controller == "igo" && ($action == "contexte" || $action == "couche" || $action == "groupe")) { if (!$this->estAnonyme() && !$this->estAuthentifie()) { return $this->forwardToLoginPage(); } else { if ($this->estRoleSelectionneRequis() && !$this->estRoleSelectionne()) { return $this->forwardToRolePage(); } } if ($this->estAnonyme() && isset($config->application->authentification->permettreAccesAnonyme) && !$config->application->authentification->permettreAccesAnonyme) { return $this->forwardToUnauthorizedPage(); } } } } }
if ($exception instanceof \Phalcon\Mvc\Dispatcher\Exception) { switch ($exception->getCode()) { case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND: //2 //2 case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND: //5 $di->getShared('session')->set('error_redirect_url', $di->get('request')->getURI()); $di->getShared('session')->set('error_exception_code', $exception->getCode()); $logInfo = '[404] '; $logInfo .= '[File] ' . $exception->getFile(); $logInfo .= ', [Line] ' . $exception->getLine(); $logInfo .= ', [Mes] ' . $exception->getMessage(); $logInfo .= ', [URI] ' . $di->get('request')->getURI(); $logInfo .= ', [ModuleName] ' . $dispatcher->getModuleName(); $logInfo .= ', [ControllerName] ' . $dispatcher->getControllerName(); $logInfo .= ', [ActionName] ' . $dispatcher->getActionName(); $logger = $di->getShared('logger_error'); $logger->log($logInfo, \Phalcon\Logger::ERROR); $di->get('response')->redirect('/home/error/show404'); return false; } } $logInfo = '[500] '; $logInfo .= '[File] ' . $exception->getFile(); $logInfo .= ', [Line] ' . $exception->getLine(); $logInfo .= ', [Mes] ' . $exception->getMessage(); $logInfo .= ', [URI] ' . $di->get('request')->getURI(); $logger = $di->getShared('logger_error'); $logger->log($logInfo, \Phalcon\Logger::ERROR); $di->getShared('session')->set('error_redirect_url', $di->get('request')->getURI());