Search code examples
magentoeventsforgot-password

Magento - change email in forgotpassword before check it


In forgot password form, i need to get the email and change it before magento check it.

Why?, beacuse i need to change a customer personal number like 9834592845 to their email store in database ([email protected])

i work with the event: controller_action_predispatch_customer_account_forgotpassword

but i can't get the email, i tried

$username = $observer->getRequest()->getPost('email');
$username = $observer->getRequest()->getPost();
$postData = Mage::app()->getRequest()->getPost();
$username = $observer->getData('email');
$username = $observer->getEmail();
$username = $_POST;
$username = $_POST['login']['username'];
$username = $_POST['login']['email'];
Mage::log($username);

and more, but nothing.

What i'm doing wrong.

I appreciate any help.


Solution

  • you can use customer_save_before Observer in that you can write your own code

    Example:

    public function detectPwdChange(Varien_Event_Observer $observer) {
        $event              = $observer->getEvent();
        $customer           = $event->getCustomer();
        $postData           = Mage::app()->getRequest()->getPost();
    
        if($customer instanceof Mage_Customer_Model_Customer && !$customer->isObjectNew()) {
    
            if( $postData['change_password'] == 1 && $postData['current_password'] != $postData['password'] ) {
                // Do something
            }
        }
    
        return $this;
    }