0

I've been building an enhanced password policy module for Magento 1.9, the specifics of which aren't causing a problem.

At the moment it hooks into admin_user_validate, fired from Mage_Admin_Model_User:563 event and validates the $observer->getUser()->getData('new_password'), which works fine when validating password changes for existing users, however I can't seem to get it to work for validating a new user's password.

I can see from Mage_Admin_Model_User that the event is only fired within the if ($this->hasNewPassword()) conditional, which wouldn't be triggered by a new user, so I guess my question is, does anyone know if there is another event that is triggered by both new and existing users, or is there a better way to validate password changes, preferably via an observer.

Any help is appreciated.

1 Answer 1

1

Try following event


<adminhtml>
    <events>
        <controller_action_predispatch_adminhtml_system_account_save>
            <observers>
                <custom_controller_action_predispatch_adminhtml_system_account_save>
                    <class>custommodule/observer</class>
                    <method>validatePasswordAdminAccountSaveAction</method>
                </custom_controller_action_predispatch_adminhtml_system_account_save>
            </observers>
        </controller_action_predispatch_adminhtml_system_account_save>
    </events>
</adminhtml>

And method is


/**
 * Validate password before admin account save action
 *
 * @param Varien_Event_Observer $observer
 */
public function validatePasswordAdminAccountSaveAction(Varien_Event_Observer $observer)
{
    $controllerAction = $observer->getEvent()->getControllerAction();
    $password = $controllerAction->getRequest()->getPost('new_password');

    if (!empty($password)) {
        if(!$this->validateAdminPassword($password)) {
            Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl('adminhtml/system_account/index'));
            Mage::app()->getResponse()->sendResponse();
            exit;
        }
    }
}
1
  • Ahh yes, the generic pre-dispatch event, how could I forget :) I'm going to mark this as correct as the logic works, but for anyone reading this in the future, the event I hooked into was controller_action_predispatch_adminhtml_permissions_user_save. Cheers Sohel.
    – MCMXCII
    Commented Apr 27, 2018 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.