Event/Observer for customer password change?
Thanks to Fabian Blechschmidt, I came up with the following that works for me (using the event customer_save_before
):
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;
}
Have a look into the code.
You can use the customer_save_after
event and just check for
/app/code/core/Mage/Customer/controllers/AccountController.php:724
$customer->setChangePassword(1);
Maybe this value is reseted, then you have to use save_before
, but I recommend to send the mail after the saving. So if this value is not readable in the after event, copy it to another attribute to have it by hand in the after event.
I wanted to do something similar, but I ended up with his code instead:
I hooked onto controller_action_postdispatch_customer_account_resetpasswordpost
function resetpasswordpost(Varien_Event_Observer $observer) {
$customer_id = Mage::app()->getRequest()->getParam('id');
$customer = Mage::getModel('customer/customer')->load($customer_id);
}
A bit more cleaner and "safer" than faffing about with the Password itself, I think!