コード例 #1
0
ファイル: Acl.php プロジェクト: julioprotzek/eventos
 /**
  * Called before an action is dispatched by Zend_Controller_Dispatcher.
  *
  * This callback allows for proxy or filter behavior.  By altering the
  * request and resetting its dispatched flag (via
  * {@link Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}),
  * the current action may be skipped.
  *
  * @param  Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $oAuth = Zend_Auth::getInstance();
     $oAcl = $this->getAcl();
     // Default role
     $sRole = 'all';
     if ($oAuth->hasIdentity()) {
         $oIdentity = $oAuth->getIdentity();
         $sRole = isset($oIdentity->sRole) ? $oIdentity->sRole : 'identify';
     }
     $sModule = $request->module;
     $sController = $request->controller;
     $sAction = $request->action;
     $sResource = $sController . ':' . $sAction;
     if ($oAcl->has($sResource)) {
         if (!$oAcl->isAllowed('all', $sResource)) {
             // Access is not allowed
             if (!$oAcl->isAllowed($sRole, $sResource)) {
                 //$flashMessenger = new Zend_Controller_Action_Helper_FlashMessenger();
                 //$flashMessenger->addMessage('Acesso negado');
                 $request->setModuleName('default');
                 $request->setControllerName('index');
                 $request->setActionName('index');
             }
         }
     } else {
         $flashMessenger = new Zend_Controller_Action_Helper_FlashMessenger();
         $flashMessenger->addMessage('Acesso negado');
         $request->setModuleName('default');
         $request->setControllerName('index');
         $request->setActionName('index');
     }
 }
コード例 #2
0
ファイル: Acl.php プロジェクト: marcelocaixeta/zf1
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $aNamespace = new Zend_Session_Namespace('userNs');
     if ($aNamespace->perfil != "") {
         $role = $aNamespace->perfil;
     } else {
         $role = 'guest';
     }
     $controller = strtolower($request->getControllerName());
     $action = strtolower($request->getActionName());
     $module = strtolower($request->getModuleName());
     $resource = $module . ':' . str_replace('-', '', $controller) . '.' . $action;
     //        $resource   = $module.':'.$controller.'.'.$action;
     if (!$this->_acl->isAllowed($role, $resource, $action)) {
         if ($this->_auth->hasIdentity()) {
             $request->setModuleName('default');
             $request->setControllerName('error');
             $request->setActionName('nopermission');
         } else {
             $this->_flashMessenger->addMessage(array('status' => 'error', 'message' => 'Favor logar novamente.'));
             $request->setModuleName('default');
             $request->setControllerName('login');
             $request->setActionName('index');
         }
     }
 }
コード例 #3
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $auth = Zend_Auth::getInstance();
     $isAllowed = false;
     $controller = $request->getControllerName();
     $action = $request->getActionName();
     // Generate the resource name
     $resourceName = $controller . '/' . $action;
     // Don't block errors
     if ($resourceName == 'error/error') {
         return;
     }
     $resources = $this->acl->getResources();
     if (!in_array($resourceName, $resources)) {
         $request->setControllerName('error')->setActionName('error')->setDispatched(true);
         throw new Zend_Controller_Action_Exception('This page does not exist', 404);
         return;
     }
     // Check if user can access this resource or not
     $isAllowed = $this->acl->isAllowed(Zend_Registry::get('role'), $resourceName);
     // Forward user to access denied or login page if this is guest
     if (!$isAllowed) {
         if (!Zend_Auth::getInstance()->hasIdentity()) {
             $forwardAction = 'login';
         } else {
             $forwardAction = 'deny';
         }
         $request->setControllerName('index')->setActionName($forwardAction)->setDispatched(true);
     }
 }
コード例 #4
0
ファイル: Timeout.php プロジェクト: marcelocaixeta/zf1
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     /**
      * Pegando o helper Redirector
      */
     $this->_redirect = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
     /*
      * Instanciando as variáveis de sessão do zend_auth
      */
     $authNamespace = new Zend_Session_Namespace('Zend_Auth');
     /**
      * Copiando em variáves o modulo, controlle e action
      */
     $module = strtolower($request->getModuleName());
     $controller = strtolower($request->getControllerName());
     $action = strtolower($request->getActionName());
     /**
      * Se o usuário estiver autenticado
      */
     if (Zend_Auth::getInstance()->hasIdentity()) {
         if (isset($authNamespace->timeout) && time() > $authNamespace->timeout) {
             /**
              * limpa a identidade do usuário que está um longo período sem acessar o controller
              */
             $request->setModuleName('default');
             $request->setControllerName('login');
             $request->setActionName('logout');
             $authNamespace->erro = 'Sua sessão expirou, favor logar novamente';
         } else {
             /**
              *  Usuário está ativo - atualizamos o time da sessão.
              */
             $authNamespace->timeout = strtotime(self::$_ZEND_SESSION_NAMESPACE_EXPIRATION_SECONDS . " seconds");
             /**
              * Renovando o timeout das variáves de sessão
              */
             $namesspaces = Zend_Session::getIterator();
             $namesspacesArrayCopy = $namesspaces->getArrayCopy();
             foreach ($namesspacesArrayCopy as $namesspace) {
                 $namesspace_each = new Zend_Session_Namespace($namesspace);
                 //$namesspace_each->setExpirationSeconds(self::$_ZEND_SESSION_NAMESPACE_EXPIRATION_SECONDS);
                 $namesspace_each->timeout = strtotime(self::$_ZEND_SESSION_NAMESPACE_EXPIRATION_SECONDS . " seconds");
                 $temp = $namesspace_each->timeout;
             }
         }
     }
     /** Se o usuário não possuir identidade ou a identidade foi removida devido ao timeout,
      * redirecionamos ele para a tela de login.
      */
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         if (!($module == 'default' && $controller == 'login' && $action == 'index') && !($module == 'default' && $controller == 'login' && $action == 'ajaxbanco')) {
             $request->setModuleName('default');
             $request->setControllerName('login');
             $request->setActionName('index');
             $request->setParam('sessao', 'expirada');
         }
         return;
     }
 }
コード例 #5
0
 /**
  * checks whether a user needs a login and is loggedin
  * otherwise redirect to login page
  *
  * @return void
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     // allways allow silent update (for easy cronjob)
     if ($request->getControllerName() == 'update' && $request->getActionName() == 'silent') {
         return;
     }
     // show login
     if ($request->getParam('login', false) !== false) {
         $request->setControllerName('index');
         $request->setActionName('login');
         return;
     }
     // logout?
     if ($request->getParam('logout', false) !== false) {
         Zend_Registry::get('session')->__unset('authenticated');
         $request->setControllerName('index');
         $request->setActionName('login');
         return;
     }
     // disallow readonly mode if user has option public not set
     if (Zend_Registry::get('session')->authenticated === 'readonly' && Zend_Registry::get('session')->public != 1) {
         Zend_Registry::get('session')->authenticated = false;
     }
     // check whether user loggedin or public access allowed
     if (Zend_Registry::get('session')->authenticated !== true && Zend_Registry::get('session')->authenticated !== 'readonly') {
         // no login required?
         $users = new application_models_users();
         if (!$users->getUsername()) {
             Zend_Registry::get('session')->authenticated = true;
             // public access allowed? start public mode
         } elseif (Zend_Registry::get('session')->public == 1) {
             Zend_Registry::get('session')->authenticated = 'readonly';
             // unallowed access -> show login window
         } else {
             $request->setControllerName('index');
             $request->setActionName('login');
             return;
         }
     }
     // load default values 4 readonly mode
     if (Zend_Registry::get('session')->authenticated === 'readonly') {
         $priorityStart = Zend_Registry::get('session')->priorityStart;
         $priorityEnd = Zend_Registry::get('session')->priorityEnd;
         // reset session with default config from config.ini
         Zend_Registry::get('bootstrap')->resetSession(false);
         // set priority slider
         Zend_Registry::get('session')->currentPriorityStart = $priorityStart;
         Zend_Registry::get('session')->currentPriorityEnd = $priorityEnd;
         Zend_Registry::get('session')->priorityStart = $priorityStart;
         Zend_Registry::get('session')->priorityEnd = $priorityEnd;
     }
     // don't allow any changings in readonly mode
     if (Zend_Registry::get('session')->authenticated !== true) {
         if ($request->getControllerName() != 'error' && $request->getControllerName() != 'index' && $request->getControllerName() != 'patch' && !($request->getControllerName() == 'item' && $request->getActionName() == 'list') && !($request->getControllerName() == 'item' && $request->getActionName() == 'listmore') && !($request->getControllerName() == 'update' && $request->getActionName() == 'silent')) {
             die('access denied');
         }
     }
 }
コード例 #6
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     try {
         $module = $request->getModuleName();
         if ($module == 'admin') {
             $moduleList = new Zend_Session_Namespace('moduleList');
             $userInfo = new Zend_Session_Namespace('userInfo');
             $module = $moduleList->module;
             $allowed_module = $userInfo->module_list;
             //generating all resources
             $acl = new Zend_Acl();
             //generating user permission
             $acl->addRole(new Zend_Acl_Role('admin'));
             $acl->addRole(new Zend_Acl_Role('anonymous'));
             $acl->add(new Zend_Acl_Resource('index'));
             $acl->add(new Zend_Acl_Resource('ajax'));
             $acl->allow('admin', 'index');
             $acl->allow('admin', 'ajax');
             if (!empty($module)) {
                 foreach ($module as $value) {
                     if (!$acl->has($value['controller'])) {
                         $acl->add(new Zend_Acl_Resource($value['controller']));
                     }
                     if (in_array($value['id'], $allowed_module)) {
                         if ($value['action'] != null) {
                             $acl->allow('admin', $value['controller'], $value['action']);
                         } else {
                             $acl->allow('admin', $value['controller']);
                         }
                     }
                 }
             }
             //allowing anonymous user to get into the login page
             $acl->allow('anonymous', 'index', 'index');
             $acl->allow('anonymous', 'index', 'login');
             $auth = Zend_Auth::getInstance();
             if ($auth->hasIdentity()) {
                 $role = 'admin';
             } else {
                 $role = 'anonymous';
             }
             $controller = $request->controller;
             $action = $request->action;
             if (!$acl->isAllowed($role, $controller, $action)) {
                 $request->setModuleName('admin');
                 $request->setControllerName('error');
                 $request->setActionName('acl');
                 $request->setParam('type', 1);
             }
         }
     } catch (Zend_Acl_Exception $e) {
         $request->setModuleName('admin');
         $request->setControllerName('error');
         $request->setActionName('acl');
         $request->setParam('type', 2);
     }
 }
コード例 #7
0
ファイル: Acl.php プロジェクト: sinaBaharlouei/google_plus
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if (PHP_SAPI == 'cli') {
         return;
     }
     $acl = new Zend_Acl();
     // add the roles
     $acl->addRole(new Zend_Acl_Role('guest'));
     $acl->addRole(new Zend_Acl_Role('user'), 'guest');
     $acl->addRole(new Zend_Acl_Role('admin'), 'user');
     // add the resources
     $acl->addResource(new Zend_Acl_Resource('index'));
     $acl->addResource(new Zend_Acl_Resource('error'));
     $acl->addResource(new Zend_Acl_Resource('user'));
     $acl->addResource(new Zend_Acl_Resource('profile'));
     $acl->addResource(new Zend_Acl_Resource('post'));
     $acl->addResource(new Zend_Acl_Resource('*'));
     // set up the access rules
     $acl->allow(null, array('index', 'error'));
     // a guest can only sign up content and login
     $acl->allow('guest', 'user', array('login', 'register', 'unique', 'search'));
     // user
     $acl->allow('user', 'user', array('edit', 'logout'));
     $acl->allow('user', 'profile', array('edit', 'profile', 'getxml', 'viewxml', 'more'));
     $acl->allow('user', 'post', array('new', 'postxml', 'getposts', 'like', 'share', 'comment', 'home', 'edit', 'allcomment', 'notification', 'report'));
     $acl->allow('admin', null);
     // Fetch the current user
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $id = get_user_id();
         $role = "user";
         if ($id == 2) {
             $role = "admin";
         }
     } else {
         $role = 'guest';
     }
     // Authorization
     $controller = $request->controller;
     $action = $request->action;
     try {
         if (!$acl->isAllowed($role, $controller, $action)) {
             if ($role == 'guest') {
                 $redirector = new Zend_Controller_Action_Helper_Redirector();
                 $redirector->gotoSimple('login', 'user');
             } else {
                 // User with role $role is not authorized for $controller/$action"
                 $request->setControllerName('error');
                 $request->setActionName('notauthorized');
             }
         }
     } catch (Exception $e) {
         $request->setControllerName('error');
         $request->setActionName('notfound');
     }
 }
コード例 #8
0
ファイル: Acl.php プロジェクト: omusico/wildfire_php
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     // set up acl
     $acl = new Zend_Acl();
     // add the roles
     $acl->addRole(new Zend_Acl_Role('guest'));
     $acl->addRole(new Zend_Acl_Role('consumer'), 'guest');
     $acl->addRole(new Zend_Acl_Role('administrator'), 'consumer');
     $acl->addRole(new Zend_Acl_Role('client'));
     // add the resources
     $acl->add(new Zend_Acl_Resource('index'));
     $acl->add(new Zend_Acl_Resource('error'));
     $acl->add(new Zend_Acl_Resource('admin'));
     $acl->add(new Zend_Acl_Resource('campaign'));
     $acl->add(new Zend_Acl_Resource('campaigninvitation'));
     $acl->add(new Zend_Acl_Resource('campaignparticipation'));
     $acl->add(new Zend_Acl_Resource('client'));
     $acl->add(new Zend_Acl_Resource('consumer'));
     $acl->add(new Zend_Acl_Resource('conversation'));
     $acl->add(new Zend_Acl_Resource('dashboard'));
     $acl->add(new Zend_Acl_Resource('forgetpassword'));
     $acl->add(new Zend_Acl_Resource('gift'));
     $acl->add(new Zend_Acl_Resource('history'));
     $acl->add(new Zend_Acl_Resource('home'));
     $acl->add(new Zend_Acl_Resource('login'));
     // set up the access rules
     $acl->allow(null, array('index', 'error'));
     // a guest can only login
     $acl->allow('guest', 'index', array('index', 'loginfailed'));
     $acl->allow('guest', 'login', array('login'));
     $acl->allow('guest', 'forgetpassword', array('index', 'sendsms', 'sendemail'));
     // consumer
     $acl->allow('consumer', 'gift', array('list', 'addtocart', 'cart', 'listorder'));
     // administrators can do anything
     $acl->allow('administrator', null);
     // fetch the current user
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $authNamespace = new Zend_Session_Namespace('Zend_Auth');
         $role = $authNamespace->role;
     } else {
         $role = 'guest';
     }
     $controller = $request->controller;
     $action = $request->action;
     if (!$acl->isAllowed($role, $controller, $action)) {
         if ($role == 'guest') {
             $request->setControllerName('index');
             $request->setActionName('index');
         } else {
             $request->setControllerName('error');
             $request->setActionName('noauth');
         }
     }
 }
コード例 #9
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if (preg_match('/(.*)\\.popup$/', $request->getControllerName(), $matches)) {
         Zend_Layout::getMvcInstance()->setInflectorTarget('../../views/scripts/:script.popup.:suffix');
         $request->setControllerName($matches[1]);
     } else {
         if (preg_match('/(.*)\\.raw$/', $request->getControllerName(), $matches)) {
             Zend_Layout::getMvcInstance()->setInflectorTarget('../../views/scripts/:script.raw.:suffix');
             $request->setControllerName($matches[1]);
         }
     }
 }
コード例 #10
0
ファイル: Acl.php プロジェクト: mtaha1990/onlineDR
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     // set up acl
     $acl = new Zend_Acl();
     // add the roles
     $acl->addRole(new Zend_Acl_Role('guest'));
     $acl->addRole(new Zend_Acl_Role('user'), 'guest');
     $acl->addRole(new Zend_Acl_Role('administrator'), 'user');
     // add the resources
     $acl->add(new Zend_Acl_Resource('index'));
     $acl->add(new Zend_Acl_Resource('error'));
     $acl->add(new Zend_Acl_Resource('page'));
     $acl->add(new Zend_Acl_Resource('menu'));
     $acl->add(new Zend_Acl_Resource('menuitem'));
     $acl->add(new Zend_Acl_Resource('user'));
     $acl->add(new Zend_Acl_Resource('search'));
     $acl->add(new Zend_Acl_Resource('feed'));
     // set up the access rules
     $acl->allow(null, array('index', 'error'));
     // a guest can only read content and login
     $acl->allow('guest', 'page', array('index', 'open'));
     $acl->allow('guest', 'menu', array('render'));
     $acl->allow('guest', 'user', array('login'));
     $acl->allow('guest', 'search', array('index', 'search'));
     $acl->allow('guest', 'feed');
     // cms users can also work with content
     $acl->allow('user', 'page', array('list', 'create', 'edit', 'delete'));
     // administrators can do anything
     $acl->allow('administrator', null);
     // fetch the current user
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $identity = $auth->getIdentity();
         $role = strtolower($identity->role);
     } else {
         $role = 'guest';
     }
     $controller = $request->controller;
     $action = $request->action;
     if (!$acl->isAllowed($role, $controller, $action)) {
         if ($role == 'guest') {
             $request->setControllerName('user');
             $request->setActionName('login');
         } else {
             $request->setControllerName('error');
             $request->setActionName('noauth');
         }
     }
 }
コード例 #11
0
ファイル: AccessControl.php プロジェクト: sura2k/sentrifugo
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $storage = new Zend_Auth_Storage_Session();
     $data = $storage->read();
     $role = $data['emprole'];
     if ($role == 1) {
         $role = 'admin';
     }
     $request->getModuleName();
     $request->getControllerName();
     $request->getActionName();
     $module = $request->getModuleName();
     $resource = $request->getControllerName();
     $privilege = $request->getActionName();
     $this->id_param = $request->getParam('id');
     $allowed = false;
     $acl = $this->_getAcl();
     $moduleResource = "{$module}:{$resource}";
     if ($resource == 'profile') {
         $role = 'viewer';
     }
     if ($resource == 'services') {
         $role = 'services';
     }
     if ($role != '') {
         if ($acl->has($moduleResource)) {
             $allowed = $acl->isAllowed($role, $moduleResource, $privilege);
         }
         if (!$allowed) {
             $request->setControllerName('error');
             $request->setActionName('error');
         }
     }
 }
コード例 #12
0
ファイル: Acl.php プロジェクト: MichaelGogeshvili/strap
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     // инициилизация объектов
     $auth = Zend_Auth::getInstance();
     $acl = Zend_Registry::get('acl');
     // если есть залогиненый пользователь
     if ($auth->hasIdentity()) {
         $role = $auth->getIdentity()->role;
     } else {
         $role = 'guest';
     }
     // если нет вообще такой роли, то будет гость
     if (!$acl->hasRole($role)) {
         $role = 'guest';
     }
     // наши ресурсы
     $controller = $request->controller;
     $action = $request->action;
     // если контроллер не существует тогда нулл
     if (!$acl->has($controller)) {
         $controller = null;
     }
     // если не существует перенаправляем на ошибку
     if (!$acl->isAllowed($role, $controller, $action)) {
         $request->setControllerName($this->_controller['controller']);
         $request->setActionName($this->_controller['action']);
     }
 }
コード例 #13
0
ファイル: Acl.php プロジェクト: Vika1994/comments
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $auth = Zend_Auth::getInstance();
     $acl = Zend_Registry::get('acl');
     //перевірка на ролі
     if ($auth->hasIdentity()) {
         $role = $auth->getIdentity()->role;
     } else {
         $role = 'guest';
     }
     //якщо ролі не існує
     if (!$acl->hasRole($role)) {
         $role = 'guest';
     }
     $controller = $request->controller;
     $action = $request->action;
     //якщо контролера не існує
     if (!$acl->has($controller)) {
         $controller = null;
     }
     //якщо юзер не має доступу
     if (!$acl->isAllowed($role, $controller, $action)) {
         $request->setControllerName($this->_controller['controller']);
         $request->setActionName($this->_controller['action']);
     }
 }
コード例 #14
0
ファイル: Auth.php プロジェクト: Neozeratul/Intermodels
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if ($this->_auth->hasIdentity()) {
         $role = $this->_auth->getIdentity()->getUser()->role;
     } else {
         $role = 'guest';
     }
     $controller = $request->controller;
     $action = $request->action;
     $module = $request->module;
     $resource = $controller;
     if (!$this->_acl->has($resource)) {
         $resource = null;
     }
     if (!$this->_acl->isAllowed($role, $resource, $action)) {
         if (!$this->_auth->hasIdentity()) {
             $module = self::NO_AUTH_MODULE;
             $controller = self::NO_AUTH_CONTROLLER;
             $action = self::NO_AUTH_ACTION;
         } else {
             $module = self::NO_ACL_MODULE;
             $controller = self::NO_ACL_CONTROLLER;
             $action = self::NO_ACL_ACTION;
         }
     }
     $request->setModuleName($module);
     $request->setControllerName($controller);
     $request->setActionName($action);
 }
コード例 #15
0
ファイル: Acl.php プロジェクト: p-artem/zend.site
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $auth = Zend_Auth::getInstance();
     $acl = Zend_Registry::get('acl');
     if ($auth->hasIdentity()) {
         $role = $auth->getIdentity()->role;
     } else {
         $role = 'guest';
     }
     if (!$acl->hasRole($role)) {
         $role = 'guest';
     }
     $controller = $request->controller;
     $action = $request->action;
     if ($controller == 'admin' && $action == 'index') {
         $this->_controller['controller'] = 'admin';
         $this->_controller['action'] = 'login';
     }
     if (!$acl->has($controller)) {
         $controller = null;
     }
     if (!$acl->isAllowed($role, $controller, $action)) {
         $request->setControllerName($this->_controller['controller']);
         $request->setActionName($this->_controller['action']);
     }
 }
コード例 #16
0
ファイル: NoRoutePlugin.php プロジェクト: nyeholt/relapse
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
     $controllerName = $request->getControllerName();
     if (empty($controllerName)) {
         $controllerName = $dispatcher->getDefaultController();
     }
     $className = $dispatcher->formatControllerName($controllerName);
     if ($className) {
         try {
             // if this fails, an exception will be thrown and
             // caught below, indicating that the class can’t
             // be loaded.
             Zend_Loader::loadClass($className, $dispatcher->getControllerDirectory());
             $actionName = $request->getActionName();
             if (empty($actionName)) {
                 $actionName = $dispatcher->getDefaultAction();
             }
             $methodName = $dispatcher->formatActionName($actionName);
             $class = new ReflectionClass($className);
             if ($class->hasMethod($methodName)) {
                 // all is well - exit now
                 return;
             }
         } catch (Zend_Exception $e) {
             // Couldn’t load the class. No need to act yet,
             // just catch the exception and fall out of the
             // if
         }
     }
     // we only arrive here if can’t find controller or action
     $request->setControllerName('noroute');
     $request->setActionName('index');
     $request->setDispatched(false);
 }
コード例 #17
0
 public function route(Zend_Controller_Request_Abstract $dispatcher)
 {
     $dispatcher->setModuleName('worker');
     $dispatcher->setControllerName('index');
     $dispatcher->setActionName('index');
     return $dispatcher;
 }
コード例 #18
0
ファイル: Auth.php プロジェクト: erickosma/e-ong
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $controller = "";
     $action = "";
     $module = "";
     /*	if($request->getControllerName() == "index" ){
     			$controller = $request->getControllerName();
     			$action     = $request->getActionName();
     			$module     = $request->getModuleName();
     		}
     		else if ( !$this->_auth->hasIdentity() ) {
     			
     		}*/
     if (!$this->_isAuthorized($request->getControllerName(), $request->getActionName())) {
         if (!$this->_auth->hasIdentity()) {
             if (!in_array($request->getControllerName(), $this->_moRedirect) && !Application_Model_Redirect::hasRequestUri()) {
                 Application_Model_Redirect::saveRequestUri("/" . $request->getControllerName() . "/" . $request->getActionName());
             }
             $controller = $this->_notLoggedRoute['controller'];
             $action = $this->_notLoggedRoute['action'];
             $module = $this->_notLoggedRoute['module'];
         } else {
             $controller = $this->_forbiddenRoute['controller'];
             $action = $this->_forbiddenRoute['action'];
             $module = $this->_forbiddenRoute['module'];
         }
     } else {
         $controller = $request->getControllerName();
         $action = $request->getActionName();
         $module = $request->getModuleName();
     }
     $request->setControllerName($controller);
     $request->setActionName($action);
     $request->setModuleName($module);
 }
コード例 #19
0
 public function route(Zend_Controller_Request_Abstract $dispatcher)
 {
     try {
         $getopt = new Zend_Console_Getopt(array('verbose|v' => 'Print verbose output', 'file|f=s' => 'File to upload'));
         $getopt->parse;
         $arguments = $getopt->getRemainingArgs();
     } catch (Zend_Console_Getopt_Exception $e) {
         echo $e->getUsageMessage();
         exit;
     }
     if ($arguments) {
         $command = array_shift($arguments);
         $action = array_shift($arguments);
         if (!preg_match('~\\W~', $command)) {
             $dispatcher->setControllerName($command);
             $dispatcher->setActionName($action);
             $dispatcher->setParams($arguments);
             if (isset($getopt->v)) {
                 $dispatcher->setParam('verbose', true);
             }
             if (isset($getopt->f)) {
                 $dispatcher->setParam('file', $getopt->f);
             }
             return $dispatcher;
         }
         echo "Invalid command.\n", exit;
     }
     echo "No command given.\n", exit;
 }
コード例 #20
0
ファイル: Admin.php プロジェクト: roycocup/Tests
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     if ('admin' == $request->getModuleName() && 'Login' != $request->getControllerName()) {
         // Immediate ACL check to make sure they have identity
         $allowUser = defined('DEBUG_MODE') ? true : false;
         // blacklist system
         $user = $request->getParam('User', null);
         if ($user instanceof Showcase_User) {
             // OK user has identity, check the roles
             //$allowUser = Zend_registry::get('Acl')->isAllowed($user->getRoles(), "CMS User") ? true : false;
             $allowUser = $user->isCmsaccess;
         }
         if (!$allowUser) {
             $request->setControllerName('Login')->setModuleName('index')->setActionName('index')->setDispatched(false);
         } else {
             Showcase_Controller_Action_HelperBroker::addPath(Package::buildPath(SITE_DIR, 'classes', 'Controller', 'Action', 'Helper', 'Admin'), 'Showcase_Controller_Action_Helper_Admin');
             // Cretae a new helper path for administrative privileges
             //$request->setParam('Admin', Showcase_Admin::getInstance());
             // Set the instance of the Admin object
             //$request->getParam('View')->assign('admin', $request->getParam('Admin'));
             // And inject it into the view so it can help things for Smarty
             // Include the CMS JS scripts
             //$request->getParam('View')->assign('javaScripts', array('/include/js/admin/js/cms'));
             // Check if the user wants to force a manual cache clearance
             //if ($request->getParam('flushCache')) {
             //	Showcase_Content_Cache::flushCache();
             //}
         }
     }
 }
コード例 #21
0
ファイル: Auth.php プロジェクト: mayconheerdt/zfSkeleton
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if (!in_array($request->getModuleName(), array('qg', 'painel'))) {
         return;
     }
     $controller = "";
     $action = "";
     $module = "";
     if (!$this->_auth->hasIdentity()) {
         $controller = $this->_notLoggedRoute['controller'];
         $action = $this->_notLoggedRoute['action'];
         $module = $request->getModuleName();
     } else {
         if (!$this->_isAuthorized($request->getModuleName(), $request->getControllerName(), $request->getActionName())) {
             $controller = $this->_forbiddenRoute['controller'];
             $action = $this->_forbiddenRoute['action'];
             $module = $request->getModuleName();
         } else {
             $controller = $request->getControllerName();
             $action = $request->getActionName();
             $module = $request->getModuleName();
         }
     }
     $request->setControllerName($controller);
     $request->setActionName($action);
     $request->setModuleName($module);
 }
コード例 #22
0
ファイル: Auth.php プロジェクト: nandorodpires2/intranet
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $this->_auth = Zend_Auth::getInstance();
     if (!$this->_auth->hasIdentity()) {
         $request->setControllerName("auth")->setActionName("login")->setDispatched();
     }
 }
コード例 #23
0
ファイル: Auth.php プロジェクト: pietka/fedit
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if ($this->_auth->hasIdentity()) {
         $role = $this->_auth->role;
     } else {
         $role = 'guest';
     }
     $controller = $request->getControllerName();
     $action = $request->getActionName();
     $module = $request->getModuleName();
     if (!$this->_acl->has($module)) {
         $module = null;
     }
     if (!$this->acl->isAllowed($role, $module)) {
         if (!$this->auth->hasIdentity()) {
             $controller = $this->_noauth['controller'];
             $action = $this->_noauth['action'];
         } else {
             $controller = $this->_noacl['controller'];
             $action = $this->_noacl['action'];
         }
     }
     $request->setModuleName($module);
     $request->setControllerName($controller);
     $request->setActionName($action);
 }
コード例 #24
0
ファイル: Cli.php プロジェクト: quincia/zf-cli
 public function route(Zend_Controller_Request_Abstract $dispatcher)
 {
     $getopt = new Zend_Console_Getopt(array());
     $arguments = $getopt->getRemainingArgs();
     $controller = 'index';
     $action = 'index';
     if ($arguments) {
         $controller = array_shift($arguments);
         if ($arguments) {
             $action = array_shift($arguments);
             $pattern_valid_action = '~^\\w+[\\-\\w\\d]+$~';
             if (false == preg_match($pattern_valid_action, $action)) {
                 echo "Invalid action {$action}.\n", exit;
             }
             if ($arguments) {
                 foreach ($arguments as $arg) {
                     $parameter = explode('=', $arg, 2);
                     if (false == isset($parameter[1])) {
                         $parameter[1] = true;
                     }
                     $dispatcher->setParam($parameter[0], $parameter[1]);
                     unset($parameter);
                 }
             }
         }
     }
     $dispatcher->setControllerName($controller)->setActionName($action);
     return $dispatcher;
 }
コード例 #25
0
ファイル: Router.php プロジェクト: null-1/fangtaitong
 /**
  * routeShutdown
  * 在 路由器 完成请求的路由后被调用
  * @param Zend_Controller_Request_Abstract $request 
  * @return void
  */
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     /**
      * 检测请求的Content-type类型
      */
     $pathinfo = $request->getPathInfo();
     if (!empty($pathinfo)) {
         if ($extension = pathinfo($pathinfo, PATHINFO_EXTENSION)) {
             if (preg_match('/^[-a-z0-9]+$/i', $extension)) {
                 $request->setParam(static::KEY_EXT, strtolower($extension));
             }
         }
     }
     /**
      * 检测是否支持json响应
      */
     if ($request->getParam(static::KEY_EXT) == '') {
         $accept = $request->getServer('HTTP_ACCEPT');
         if (!empty($accept)) {
             if (strpos($accept, 'json') !== false) {
                 $request->setParam(static::KEY_EXT, 'json');
             }
         }
     }
     /**
      * 格式化请求目标信息,不允许[-a-zA-Z0-9]以外的字符
      */
     $pattern = '/[^-a-zA-Z0-9].*/';
     $request->setModuleName(preg_replace($pattern, '', $request->getModuleName()));
     $request->setControllerName(preg_replace($pattern, '', $request->getControllerName()));
     $request->setActionName(preg_replace($pattern, '', $request->getActionName()));
 }
コード例 #26
0
ファイル: AuthPlugin.php プロジェクト: stevenli/360ic.net.cn
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if ('company' == $request->getControllerName()) {
         $tsn = $request->tsn ? $request->tsn : $_COOKIE['tsn'];
         if ($tsn) {
             $token = Token::create($tsn);
             $token->update_sync_time();
         } else {
             $token = Token::create_abstract('123');
         }
         if ($token->is_logined() == true) {
             if ($token->is_expire()) {
                 $token->destroy();
                 include_once LIB_PATH . '/view_helper/BuildUrl.php';
                 $url_builder = new Zend_View_Helper_BuildUrl();
                 $referer = SearchFilter::slashes($url_builder->buildUrl($request->getActionName(), $request->getControllerName(), $request->getModuleName()));
                 $login_url = $url_builder->buildUrl('login', 'auth', 'index', array('redirect' => $referer));
                 $redirector = new Zend_Controller_Action_Helper_Redirector();
                 $redirector->gotoUrl($login_url);
                 return;
             }
             $token->register();
         } else {
             if ('auth' != $request->getActionName()) {
                 $token->destroy();
                 $request->setModuleName('index');
                 $request->setControllerName('auth');
                 $request->setActionName('login');
             }
         }
     }
 }
コード例 #27
0
ファイル: Acl.php プロジェクト: pansot2/PadCMS-backend
 /**
  * @param Zend_Controller_Request_Abstract $oHttpRequest
  */
 public function preDispatch(Zend_Controller_Request_Abstract $oHttpRequest)
 {
     $sControllerName = $oHttpRequest->getControllerName();
     $sActionName = $oHttpRequest->getActionName();
     $aRequestedParams = $oHttpRequest->getUserParams();
     $sQuery = '';
     unset($aRequestedParams['controller']);
     unset($aRequestedParams['action']);
     // Define user role
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $aData = Zend_Auth::getInstance()->getStorage()->read();
         $sRole = $aData['role'];
     } else {
         // Default role
         $sRole = 'guest';
     }
     // Check access
     if (!$this->_oAcl->isAllowed($sRole, $sControllerName, $sActionName)) {
         $oHttpRequest->setParam('referer_controller', $sControllerName);
         $oHttpRequest->setParam('referer_action', $sActionName);
         $aParams = array();
         if (count($aRequestedParams)) {
             foreach ($aRequestedParams as $sKey => $sValue) {
                 $aParams[] = $sKey;
                 $aParams[] = $sValue;
             }
             $sQuery = implode('/', $aParams) . '/';
         }
         $oHttpRequest->setParam('query', $sQuery);
         $oHttpRequest->setControllerName('auth')->setActionName('login');
         $this->_response->setHttpResponseCode(401);
     }
 }
コード例 #28
0
ファイル: SetPagePath.php プロジェクト: ngukho/ducbui-cms
 /**
  * this function routes all requests that come in to the default module to the index controller / index action
  *
  * @param zend_controller_request $request
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if ($request->module == 'public' && $request->controller != 'plugin') {
         $request->setControllerName('index');
         $request->setActionName('index');
     }
 }
コード例 #29
0
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
 {
     $authNamespace = new Zend_Session_Namespace('Gslab_Session');
     $controller = $request->getParam('controller');
     $action = $request->getParam('action');
     $module = $request->getParam('module');
     $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
     if (!$this->_auth->hasIdentity() && $module == 'default' && $controller != 'login') {
         $redirect = '/';
         if ($action != 'index') {
             $redirect = '/' . $action . $redirect;
         }
         if ($controller != 'index' || $action != 'index') {
             $redirect = '/' . $controller . $redirect;
         }
         if ($module != 'default') {
             $redirect = '/' . $module . $redirect;
         }
         $redirect = urlencode($redirect);
         //$this->getResponse()->setRedirect($baseUrl . '/admin/login?redirect=' . $redirect, 302);
         $request->setModuleName('default');
         $request->setControllerName('login');
         $request->setActionName('index');
     }
 }
コード例 #30
0
ファイル: Auth.php プロジェクト: romulotorres/ZendBase
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if (!Zend_Auth::getInstance()->hasIdentity() && ($request->getControllerName() != 'index' && $request->getControllerName() != 'error')) {
         $request->setControllerName('index');
         $request->setActionName('index');
     }
 }