コード例 #1
0
ファイル: InstallCheck.php プロジェクト: KasaiDot/FansubCMS
 /**
  * check if the cms is already installed or needs update and redirect to installer in one of these cases
  * @see Zend_Controller_Plugin_Abstract::preDispatch()
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if ($this->getRequest()->getModuleName() == 'install' || $this->getRequest()->getModuleName() == 'devtools') {
         # we don't need to check while we are in the installer itself
         return;
     }
     # check whether the cms is installed or not
     $t = Doctrine::getTable('User_Model_User');
     try {
         $t->count();
         $installed = true;
     } catch (Doctrine_Exception $e) {
         $installed = false;
     }
     $redirect = new Zend_Controller_Action_Helper_Redirector();
     if ($installed) {
         # check if update is needed
         $mig = Install_Api_Migration::getInstance();
         if ($mig->getCurrentVersion() < $mig->getLatestVersion()) {
             # update needed
             $redirect->gotoSimple('index', 'index', 'install');
         }
     } else {
         $redirect->gotoSimple('index', 'index', 'install');
     }
 }
コード例 #2
0
ファイル: Action.php プロジェクト: ajbrown/bitnotion
 public function checkAuth()
 {
     if (!$this->isPublic() && !Zend_Auth::getInstance()->hasIdentity()) {
         $this->_flash->addMessage('You must be logged in');
         $this->_redirector->gotoSimple('login', 'account');
     }
 }
コード例 #3
0
 /**
  * Switch the actual theme seting it on session
  * 
  * @todo improve it to persist the theme through sessions
  */
 public function switchAction()
 {
     if ($this->_hasParam("to")) {
         $themeSession = new Zend_Session_Namespace("theme");
         $themeSession->themeName = $this->_getParam("to");
     }
     $this->_redirector->gotoSimple("index", "index", "aganacore");
 }
コード例 #4
0
ファイル: RedirectorTest.php プロジェクト: rexmac/zf2
 public function testPassingDefaultModuleShouldNotRenderModuleNameInRedirectUrl()
 {
     $this->request->setModuleName('admin')->setControllerName('class')->setActionName('view');
     $this->redirector->gotoSimple('login', 'account', 'application');
     $test = $this->redirector->getRedirectUrl();
     $this->assertEquals('/account/login', $test, $test);
 }
コード例 #5
0
ファイル: Acl.php プロジェクト: KasaiDot/FansubCMS
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $this->_initAcl();
     if ($this->_auth->hasIdentity()) {
         $ident = $this->_auth->getIdentity();
         $date = new Zend_Date();
         $ident->last_login = $date->get(DATABASE_DATE_FORMAT);
         $ident->save();
     }
     if ($request->getControllerName() != 'admin' && $request->getModuleName() != 'admin') {
         return;
     }
     // if this is not admin skip the rest
     if (!$this->_auth->hasIdentity() && !($request->getControllerName() == 'auth' && $request->getActionName() == 'login' && $request->getModuleName() == 'admin')) {
         $redirect = new Zend_Controller_Action_Helper_Redirector();
         $redirect->gotoSimple('login', 'auth', 'admin');
     }
     if ($request->getModuleName() == 'user' && $request->getControllerName() == 'admin' && $request->getActionName() == 'profile') {
         return;
     }
     // the profile is a free resource
     $resource = $request->getModuleName() . '_' . $request->getControllerName();
     $hasResource = $this->_acl->has($resource);
     if ($hasResource && !$this->_acl->isAllowed('fansubcms_user_custom_role_logged_in_user', $resource, $request->getActionName())) {
         throw new FansubCMS_Exception_Denied('The user is not allowd to do this');
     }
 }
コード例 #6
0
ファイル: class.auth.php プロジェクト: rosslittle/Email-Check
 public function logout()
 {
     $auth = Zend_Auth::getInstance();
     $auth->clearIdentity();
     $storage = $auth->getStorage();
     $storage->clear();
     $controller = new Zend_Controller_Action_Helper_Redirector();
     $controller->gotoSimple('index');
 }
コード例 #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
 /** @group ZF-6025 */
 public function testGotoSimpleShouldNotHardcodeControllerActionModuleKeys()
 {
     $this->request->setControllerKey('foo')->setActionKey('bar')->setModuleKey('baz');
     $this->router->removeRoute('default');
     $this->router->addRoute('default', new Zend_Controller_Router_Route(':baz/:foo/:bar/*', array('baz' => 'default', 'foo' => 'index', 'bar' => 'index')));
     $this->redirector->gotoSimple('babar', 'barbapapa', 'barbazoo', array('asd' => 1));
     $result = $this->redirector->getRedirectUrl();
     $expected = '/barbazoo/barbapapa/babar/asd/1';
     $this->assertEquals($expected, $result);
 }
コード例 #9
0
ファイル: Action.php プロジェクト: belapp/opus4-application
 /**
  * Method called when access to module has been denied.
  */
 public function moduleAccessDeniedAction()
 {
     // we are not allowed to access this module -- but why?
     $identity = Zend_Auth::getInstance()->getIdentity();
     $errorcode = 'no_identity_error';
     if (!empty($identity)) {
         $errorcode = 'wrong_identity_error';
     }
     // Forward to module auth
     $this->_flashMessenger->addMessage(array('level' => 'failure', 'message' => $errorcode));
     $this->_redirector->gotoSimple('index', 'auth', 'default');
 }
コード例 #10
0
ファイル: AuthPlugin.php プロジェクト: VUW-SIM-FIS/emiemi
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if (!Zend_Auth::getInstance()->hasIdentity() && !in_array($this->getRequest()->getControllerName(), array('index', 'login', 'api', 'install', 'error', 'test'))) {
         $redirect = new Zend_Controller_Action_Helper_Redirector();
         $redirect->gotoSimple('index', 'login', null, array('next' => str_replace("/", ";", $this->getRequest()->getRequestUri())));
     }
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $view = Zend_Layout::getMvcInstance()->getView();
         $view->loginStatus = true;
         $view->user = Zend_Auth::getInstance()->getIdentity();
     }
 }
コード例 #11
0
ファイル: RedirectorTest.php プロジェクト: nbcutech/o3drupal
 /**
  * @group ZF-10364
  */
 public function testGotoSimpleDefaultModuleRedirectsToDefaultModule()
 {
     $this->controller->getFrontController()->setDefaultModule('test')->setDefaultControllerName('test')->setDefaultAction('test');
     $this->redirector->gotoSimple('test', 'test', 'test');
     $result = $this->redirector->getRedirectUrl();
     $expected = '/';
     $this->assertEquals($expected, $result);
     $this->redirector->gotoSimple('index', 'index', 'default');
     $result = $this->redirector->getRedirectUrl();
     $expected = '/default/index/index';
     $this->assertEquals($expected, $result);
 }
コード例 #12
0
 /**
  * Verifica se o usuário está logado no sistema
  *
  * @return boolean
  */
 protected function checkIdentity()
 {
     // Ignora a checagem quando for a instalação do sistema
     if ($this->getRequest()->getControllerName() == 'instalacao') {
         return FALSE;
     }
     // Verifica se o usuário está logado no sistema
     if (!Zend_Auth::getInstance()->hasIdentity() || !is_object($this->view->user->getEntity())) {
         $this->_helper->getHelper('FlashMessenger')->addMessage(array('error' => 'Você precisa estar logado para acessar essa página'));
         $this->_redirector->gotoSimple('index', 'login', 'auth');
     }
     return TRUE;
 }
コード例 #13
0
 public function activateAction()
 {
     $request = $this->getRequest()->getQuery();
     if (!isset($request['key'])) {
         $this->getLog()->err("Activation failed");
         $redirect = new Zend_Controller_Action_Helper_Redirector();
         $redirect->gotoSimple('index', 'index', null);
     }
     $user = new Model_User();
     if (!$user->activate($request['key'])) {
         $this->getLog()->err("Activation failed for key " . $request['key']);
         $redirect = new Zend_Controller_Action_Helper_Redirector();
         $redirect->gotoSimple('index', 'index', null);
     }
     $this->getLog()->info("Activation successful for {$user}");
 }