/** * Authorize store access * * @param Mage_Core_Controller_Varien_Action $action */ protected function _authorizeFrontendAccess($action) { /* @var $session Mage_Customer_Model_Session */ $session = Mage::getSingleton('customer/session'); /* @var $helper Tangkoko_Authorization_Helper_Store */ $helper = Mage::helper('tangkoko_authorization/store'); // Check if customer is authorized if (!$helper->isAuthorized($session->getCustomer())) { $request = $action->getRequest(); $path = $action->getFullActionName('/'); $allowedActions = $helper->getPublicActions(); if ($allowedActions != "" && preg_match($allowedActions, $path)) { // Do not redirect on allowed actions return; } elseif (preg_match('#^cms/#', $path)) { // Do not redirect on allowed CMS page $identifier = $request->getParam('page_id', $request->getParam('id', Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE))); $page = Mage::getModel('cms/page')->load($identifier); if (in_array($page->getIdentifier(), $helper->getPublicCmsPages())) { return; } } // Path is not an allowed page or action $url = null; $parameters = array(); $message = null; $redirectMode = null; // Define redirect mode if ($session->isLoggedIn()) { // Customer is loged in $redirectMode = $helper->getUnauthorizedCustomerRedirect(); } else { // Customer is not logged in $redirectMode = $helper->getAnonymousCustomerRedirect(); } // Define redirection parameters depending on redirect mode if ($redirectMode == Tangkoko_Authorization_Helper_Store::PAGE_REDIRECT) { // Page redirection $url = $helper->getErrorPage(); } elseif ($redirectMode == Tangkoko_Authorization_Helper_Store::CUSTOM_REDIRECT) { // Url redirection $url = $helper->getCustomRedirectUrl(); } elseif ($redirectMode == Tangkoko_Authorization_Helper_Store::LOGIN_REDIRECT) { // Visitor with redirect mode equal to login $url = Mage_Customer_Helper_Data::ROUTE_ACCOUNT_LOGIN; $parameters = Mage::helper('customer')->getLoginUrlParams(); } // Get redirect message $message = $helper->getErrorMessage(); if (!empty($message)) { $errorMessage = new Mage_Core_Model_Message_Error($message); $session->addUniqueMessages($errorMessage); } return Mage::app()->getResponse()->setRedirect(Mage::getUrl($url, $parameters)); } }
/** * @magentoAppIsolation enabled */ public function testAddPageLayoutHandles() { $this->_model->getRequest()->setRouteName('test')->setControllerName('controller')->setActionName('action'); //$this->_model->addPageLayoutHandles(array()); $this->assertEmpty($this->_model->getLayout()->getUpdate()->getHandles()); $this->_model->getRequest()->setRouteName('catalog')->setControllerName('product')->setActionName('view'); $this->_model->addPageLayoutHandles(array('type' => 'simple')); $handles = $this->_model->getLayout()->getUpdate()->getHandles(); $this->assertContains('default', $handles); $this->assertContains('catalog_product_view', $handles); $this->assertContains('catalog_product_view_type_simple', $handles); }
public function testNoRouteAction() { $status = 'test'; $this->_model->getRequest()->setParam('__status__', $status); $caughtException = false; $message = ''; try { $this->_model->norouteAction(); } catch (Exception $e) { $caughtException = true; $message = $e->getMessage(); } $this->assertFalse($caughtException, $message); }
/** * Authenticate controller action by login customer * * @param Mage_Core_Controller_Varien_Action $action * @param bool $loginUrl * @return bool */ public function authenticate(Mage_Core_Controller_Varien_Action $action, $loginUrl = null) { if (!$this->_getSession()->isLoggedIn()) { if ($action->getRequest()->isAjax()) { $this->_getSession()->setBeforeVendorAuthUrl(Mage::getUrl('*/vendor/', array('_current' => true, '_secure' => true, '_nosid' => true))); } else { $oAuthUrl = Mage::getUrl('*/*/*', array('_current' => true, '_secure' => true, '_nosid' => true)); $this->_getSession()->setBeforeVendorAuthUrl($oAuthUrl); } if (is_null($loginUrl)) { if (Mage::getConfig()->getModuleConfig('Ced_CsVendorPanel')->is('active', 'true')) { $url = 'csmarketplace/account/login'; } else { $url = 'customer/account/login'; } $loginUrl = Mage::getUrl($url, array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure(), '_nosid' => true)); } if ($action->getRequest()->isAjax()) { $ajaxResponse = array(); $ajaxResponse['ajaxExpired'] = true; $ajaxResponse['ajaxRedirect'] = $loginUrl; $action->getResponse()->setBody(json_encode($ajaxResponse)); return; } $action->getResponse()->setRedirect($loginUrl); return false; } if ($this->_getSession()->isLoggedIn() && Mage::helper('csmarketplace')->authenticate($this->_getSession()->getCustomerId())) { $vendor = Mage::getModel('csmarketplace/vendor')->loadByCustomerId($this->_getSession()->getCustomerId()); if ($vendor && $vendor->getId()) { $this->_getSession()->setData('vendor_id', $vendor->getId()); $this->_getSession()->setData('vendor', $vendor); Mage::dispatchEvent('ced_csmarketplace_vendor_authenticate_after', array('session' => $this->_getSession())); } } Mage::dispatchEvent('ced_csmarketplace_vendor_acl_check', array('current' => $this, 'action' => $action)); return $this->_allowedResource; }