|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of the FIREGENTO project. |
| 4 | + * |
| 5 | + * FireGento_Core is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU General Public License version 3 as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This script is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 12 | + * |
| 13 | + * PHP version 5 |
| 14 | + * |
| 15 | + * @category FireGento |
| 16 | + * @package FireGento_Customer |
| 17 | + * @author FireGento Team <team@firegento.com> |
| 18 | + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. |
| 19 | + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) |
| 20 | + * @version $$Id$$ |
| 21 | + */ |
| 22 | +/** |
| 23 | + * Helper class |
| 24 | + * |
| 25 | + * @category FireGento |
| 26 | + * @package FireGento_Customer |
| 27 | + * @author FireGento Team <team@firegento.com> |
| 28 | + * @copyright 2013 FireGento Team (http://www.firegento.de). All rights served. |
| 29 | + * @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3) |
| 30 | + * @version $$Id$$ |
| 31 | + */ |
| 32 | +class FireGento_Customer_Helper_Redirect extends FireGento_Customer_Helper_Data |
| 33 | +{ |
| 34 | + |
| 35 | + /** |
| 36 | + * Define target URL and redirect customer after logging in |
| 37 | + */ |
| 38 | + public function _loginPostRedirect() |
| 39 | + { |
| 40 | + $session = $this->_getSession(); |
| 41 | + |
| 42 | + if (!$session->getBeforeAuthUrl() || $session->getBeforeAuthUrl() == Mage::getBaseUrl()) { |
| 43 | + // Set default URL to redirect customer to |
| 44 | + $session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl()); |
| 45 | + // Redirect customer to the last page visited after logging in |
| 46 | + if ($session->isLoggedIn()) { |
| 47 | + if (!Mage::getStoreConfigFlag( |
| 48 | + Mage_Customer_Helper_Data::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD |
| 49 | + )) { |
| 50 | + $referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME); |
| 51 | + if ($referer) { |
| 52 | + // Rebuild referer URL to handle the case when SID was changed |
| 53 | + $referer = Mage::getModel('core/url') |
| 54 | + ->getRebuiltUrl(Mage::helper('core')->urlDecode($referer)); |
| 55 | + if ($this->_isUrlInternal($referer)) { |
| 56 | + $session->setBeforeAuthUrl($referer); |
| 57 | + } |
| 58 | + } |
| 59 | + } else if ($session->getAfterAuthUrl()) { |
| 60 | + $session->setBeforeAuthUrl($session->getAfterAuthUrl(true)); |
| 61 | + } |
| 62 | + } else { |
| 63 | + $session->setBeforeAuthUrl(Mage::helper('customer')->getLoginUrl()); |
| 64 | + } |
| 65 | + } else if ($session->getBeforeAuthUrl() == Mage::helper('customer')->getLogoutUrl()) { |
| 66 | + $session->setBeforeAuthUrl(Mage::helper('customer')->getDashboardUrl()); |
| 67 | + } else { |
| 68 | + if (!$session->getAfterAuthUrl()) { |
| 69 | + $session->setAfterAuthUrl($session->getBeforeAuthUrl()); |
| 70 | + } |
| 71 | + if ($session->isLoggedIn()) { |
| 72 | + $session->setBeforeAuthUrl($session->getAfterAuthUrl(true)); |
| 73 | + } |
| 74 | + } |
| 75 | + $this->_redirectUrl($session->getBeforeAuthUrl(true)); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * |
| 80 | + * @return Mage_Core_Controller_Request_Http |
| 81 | + */ |
| 82 | + public function getRequest() |
| 83 | + { |
| 84 | + return Mage::app()->getRequest(); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * |
| 89 | + * @return Mage_Core_Controller_Response_Http |
| 90 | + */ |
| 91 | + public function getResponse() |
| 92 | + { |
| 93 | + return Mage::app()->getResponse(); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Retrieve customer session model object |
| 98 | + * |
| 99 | + * @return Mage_Customer_Model_Session |
| 100 | + */ |
| 101 | + public function _getSession() |
| 102 | + { |
| 103 | + return Mage::getSingleton('customer/session'); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Check url to be used as internal |
| 108 | + * |
| 109 | + * @param string $url |
| 110 | + * @return bool |
| 111 | + */ |
| 112 | + public function _isUrlInternal($url) |
| 113 | + { |
| 114 | + if (strpos($url, 'http') !== false) { |
| 115 | + /** |
| 116 | + * Url must start from base secure or base unsecure url |
| 117 | + */ |
| 118 | + if ((strpos($url, Mage::app()->getStore()->getBaseUrl()) === 0) |
| 119 | + || (strpos($url, Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true)) === 0) |
| 120 | + ) { |
| 121 | + return true; |
| 122 | + } |
| 123 | + } |
| 124 | + return false; |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * Set redirect url into response |
| 129 | + * |
| 130 | + * @param string $url |
| 131 | + * @return Mage_Core_Controller_Varien_Action |
| 132 | + */ |
| 133 | + public function _redirectUrl($url) |
| 134 | + { |
| 135 | + $this->getResponse()->setRedirect($url); |
| 136 | + return $this; |
| 137 | + } |
| 138 | +} |
0 commit comments