示例#1
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     try {
         $acl = new Engine_Vault_Acl();
         //$this->_session = Zend_Registry::get('sessionNamespace');
         //			print_r($this->_role);die("test");die("test");
         if ($this->_auth->hasIdentity()) {
             //                            echo "<pre>";
             //                                                        print_r($this->_role);die("test");
             $this->_role = isset($this->_session->storage->role) ? $this->_session->storage->role : $this->_role;
             if (isset($this->_session->storage->role)) {
                 switch ($this->_session->storage->role) {
                     case 0:
                         $this->_role = $this->_role;
                         break;
                     case 1:
                         $this->_role = 'user';
                         break;
                     case 2:
                         $this->_role = 'admin';
                         break;
                     case 4:
                         $this->_role = 'agent';
                         break;
                     default:
                         break;
                 }
             }
             //
             //                                echo ($this->_role);die;
             $this->_resourceModule = $request->getModuleName();
             $this->_resourceController = $request->getControllerName();
             $this->_resourceActionName = $request->getActionName();
             $this->_resourceString = $this->_resourceModule . '::' . $this->_resourceController . '::' . $this->_resourceActionName;
             $this->_redirectUrl = $request->getPathInfo();
             $this->_session->redirectUrl = $this->_redirectUrl;
             if ($this->_env != "production") {
                 $this->_logger->info($this->_role . $this->_resourceString);
             }
             try {
                 if ($acl->isAllowed($this->_role, $this->_resourceString)) {
                     $this->_access = 1;
                 } else {
                     $this->_access = 0;
                 }
             } catch (Exception $e) {
                 $this->getResponse()->setHttpResponseCode(404);
                 throw new Exception($e->getMessage());
             }
             if (!$this->_access) {
                 $this->getResponse()->setHttpResponseCode(403);
                 throw new Exception('Access Forbidden', 403);
             }
         } else {
             $this->_resourceModule = $request->getModuleName();
             $this->_resourceController = $request->getControllerName();
             $this->_resourceActionName = $request->getActionName();
             $this->_resourceString = $this->_resourceModule . '::' . $this->_resourceController . '::' . $this->_resourceActionName;
             $this->_redirectUrl = $request->getPathInfo();
             $this->_session->redirectUrl = $this->_redirectUrl;
             if ($this->_env != "production") {
                 $this->_logger->info($this->_role . $this->_resourceString);
             }
             try {
                 if ($acl->isAllowed($this->_role, $this->_resourceString)) {
                     $this->_access = 1;
                 } else {
                     $this->_access = 0;
                 }
             } catch (Exception $e) {
                 $this->getResponse()->setHttpResponseCode(404);
                 throw new Exception($e->getMessage());
             }
             if (!$this->_access) {
                 //DEV :priyanka varanasi
                 //DESC: TO redirect user to the home page if access permissions will get violated according to the module.
                 $module = $request->getModuleName();
                 if ($module == 'admin') {
                     Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->setGotoUrl('/admin');
                 } else {
                     if ($module == 'agent') {
                         Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->setGotoUrl('/agent');
                     } else {
                         if ($module == 'web') {
                             Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->setGotoUrl('/');
                         } else {
                             Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->setGotoUrl('/');
                         }
                     }
                 }
             }
         }
         // do something that throws an exception
     } catch (Exception $e) {
         Zend_Registry::get('logger')->info($e);
         // Repoint the request to the default error handler
         $request->setModuleName('home');
         $request->setControllerName('error');
         $request->setActionName('error');
         // Set up the error handler
         $error = new Zend_Controller_Plugin_ErrorHandler();
         $error->type = Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER;
         $error->request = clone $request;
         $error->exception = $e;
         $request->setParam('error_handler', $error);
     }
 }
示例#2
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     //        die('roop');
     try {
         $acl = new Engine_Vault_Acl();
         $front = Zend_Controller_Front::getInstance();
         if ($this->_isAjax) {
             Zend_Layout::getMvcInstance()->disableLayout();
         }
         //                        print_r($this->_auth->hasIdentity());die('123');
         if ($this->_auth->hasIdentity()) {
             //echo $this->_session->storage->role;die;
             $this->_role = isset($this->_session->storage->role) ? $this->_session->storage->role : $this->_role;
             if (isset($this->_session->storage->role)) {
                 //                                    print_r($this->_session->storage->role); die;
                 switch ($this->_session->storage->role) {
                     case 0:
                         //   $this->_session->storage->role = 'guest';
                         $this->_role = $this->_role;
                         break;
                     case 1:
                         //  $this->_session->storage->role = 'user';
                         $this->_role = 'user';
                         break;
                     case 2:
                         // $this->_session->storage->role = 'admin';
                         $this->_role = 'admin';
                         break;
                     default:
                         break;
                 }
             }
             $this->_resourceModule = $request->getModuleName();
             $this->_resourceController = $request->getControllerName();
             $this->_resourceActionName = $request->getActionName();
             $this->_resourceString = $this->_resourceModule . '::' . $this->_resourceController . '::' . $this->_resourceActionName;
             $this->_redirectUrl = $request->getPathInfo();
             $this->_session->redirectUrl = $this->_redirectUrl;
             if ($this->_env != "production") {
                 $this->_logger->info($this->_role . $this->_resourceString);
             }
             try {
                 if ($acl->isAllowed($this->_role, $this->_resourceString)) {
                     $this->_access = 1;
                 } else {
                     $this->_access = 0;
                 }
             } catch (Exception $e) {
                 $this->getResponse()->setHttpResponseCode(404);
                 throw new Exception($e->getMessage());
             }
             //				if(!$this->_access){
             //
             //					$this->getResponse()->setHttpResponseCode(403);
             //					throw new Exception('Access Forbidden',403);
             //				}
         } else {
             $this->_resourceModule = $request->getModuleName();
             $this->_resourceController = $request->getControllerName();
             $this->_resourceActionName = $request->getActionName();
             $this->_resourceString = $this->_resourceModule . '::' . $this->_resourceController . '::' . $this->_resourceActionName;
             $this->_redirectUrl = $request->getPathInfo();
             $this->_session->redirectUrl = $this->_redirectUrl;
             if ($this->_env != "production") {
                 $this->_logger->info($this->_role . $this->_resourceString);
             }
             try {
                 if ($acl->isAllowed($this->_role, $this->_resourceString)) {
                     $this->_access = 1;
                 } else {
                     $this->_access = 0;
                 }
             } catch (Exception $e) {
                 $this->getResponse()->setHttpResponseCode(404);
                 //					throw new Exception($e->getMessage());
             }
             if (!$this->_access) {
                 //					$this->getResponse()->setHttpResponseCode(403);
                 //					throw new Exception('Access Forbidden',403);
                 Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->setGotoUrl('/');
             }
         }
         // do something that throws an exception
     } catch (Exception $e) {
         //                    print_r($e);
         Zend_Registry::get('logger')->info($e);
         // Repoint the request to the default error handler
         $request->setModuleName('user');
         $request->setControllerName('error');
         $request->setActionName('error');
         // Set up the error handler
         $error = new Zend_Controller_Plugin_ErrorHandler();
         $error->type = Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER;
         $error->request = clone $request;
         $error->exception = $e;
         $request->setParam('error_handler', $error);
     }
 }