Skip to content

Commit 990e745

Browse files
committed
Merge pull request #8 from mklooss/master
fixed 500 Error if email does not exists
2 parents 79f5670 + 3967a88 commit 990e745

File tree

5 files changed

+145
-9
lines changed

5 files changed

+145
-9
lines changed

src/app/code/community/FireGento/Customer/Helper/Data.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
3030
* @version $$Id$$
3131
*/
32-
class FireGento_Customer_Helper_Data extends Mage_Core_Helper_Abstract
32+
class FireGento_Customer_Helper_Data extends Mage_Customer_Helper_Data
3333
{
3434

35-
}
35+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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+
}

src/app/code/community/FireGento/Customer/Model/Observer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ public function validateCustomerActivationBeforeLogin(Varien_Event_Observer $obs
131131
);
132132

133133
// Redirect to login page
134-
$loginUrl = Mage::helper('customer')->getLoginUrl();
135-
$controller->getResponse()->setRedirect($loginUrl);
136-
$controller->getResponse()->sendResponse();
134+
Mage::helper('firegento_customer/redirect')->_loginPostRedirect();
137135
}
138136
return $this;
139137
}

src/app/code/community/FireGento/Customer/etc/config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</FireGento_Customer>
6363
</modules>
6464
</translate>
65-
<events>
65+
<events>
6666
<customer_save_before>
6767
<observers>
6868
<firegento_customer_observer>
@@ -117,4 +117,4 @@
117117
</password>
118118
</customer>
119119
</default>
120-
</config>
120+
</config>

src/app/code/community/FireGento/Customer/etc/system.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@
5353
</password>
5454
</groups>
5555
</customer>
56-
</sections>
57-
</config>
56+
</sections>
57+
</config>

0 commit comments

Comments
 (0)