Skip to content

Commit 24cd60d

Browse files
pquernerPascal Quernersreichelkiatng
authored
#4933 fix: check email validity before attempting to save email or check if password request is allowed (#4934)
* #4933 fix: check email validity before attempting to save email or check if password request is allowed * 4933 chore: run phpcs fixer on this file * Refactor password reset flow handling Modify the customer forgot‑password flow to not save emails beyond the configured limits + 1. * Fixed rector. --------- Co-authored-by: Pascal Querner <[email protected]> Co-authored-by: Sven Reichel <[email protected]> Co-authored-by: Ng Kiat Siong <[email protected]>
1 parent 4516833 commit 24cd60d

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

app/code/core/Mage/Customer/controllers/AccountController.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,14 @@ public function forgotPasswordPostAction()
715715
{
716716
$email = (string) $this->getRequest()->getPost('email');
717717
if ($email) {
718+
if (!Zend_Validate::is($email, 'EmailAddress')) {
719+
$this->_getSession()->setForgottenEmail($email);
720+
$this->_getSession()->addError($this->__('Invalid email address.'));
721+
$this->_redirect('*/*/forgotpassword');
722+
return;
723+
}
724+
718725
$flowPassword = Mage::getModel('customer/flowpassword');
719-
$flowPassword->setEmail($email)->save();
720726

721727
if (!$flowPassword->checkCustomerForgotPasswordFlowEmail($email)) {
722728
$this->_getSession()
@@ -731,33 +737,29 @@ public function forgotPasswordPostAction()
731737
return;
732738
}
733739

734-
if (!Zend_Validate::is($email, 'EmailAddress')) {
735-
$this->_getSession()->setForgottenEmail($email);
736-
$this->_getSession()->addError($this->__('Invalid email address.'));
737-
$this->_redirect('*/*/forgotpassword');
738-
return;
739-
}
740-
741740
$customer = Mage::getModel('customer/customer')
742741
->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
743742
->loadByEmail($email);
744743

745744
$customerId = $customer->getId();
746-
if ($customerId) {
747-
try {
745+
746+
try {
747+
$flowPassword->setEmail($email)->save();
748+
if ($customerId) {
748749
/** @var Helper $helper */
749750
$helper = $this->_getHelper('customer');
750751
$newResetPasswordLinkToken = $helper->generateResetPasswordLinkToken();
751752
$newResetPasswordLinkCustomerId = $helper->generateResetPasswordLinkCustomerId($customerId);
752753
$customer->changeResetPasswordLinkCustomerId($newResetPasswordLinkCustomerId);
753754
$customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
754755
$customer->sendPasswordResetConfirmationEmail();
755-
} catch (Exception $exception) {
756-
$this->_getSession()->addError($exception->getMessage());
757-
$this->_redirect('*/*/forgotpassword');
758-
return;
759756
}
757+
} catch (Exception $exception) {
758+
$this->_getSession()->addError($exception->getMessage());
759+
$this->_redirect('*/*/forgotpassword');
760+
return;
760761
}
762+
761763
$this->_getSession()
762764
->addSuccess($this->_getHelper('customer')
763765
->__(

0 commit comments

Comments
 (0)