Magento: Extending Customer Account Controller to add actions to the forgot password steps

Magento: Extending Customer Account Controller to add actions to the forgot password steps

August 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Extending Customer Account Controller to add actions to the forgot password steps

Magento: Extending Customer Account Controller for Custom Forgot Password Actions

As an experienced Magento developer, I often encounter scenarios where clients need to extend the default behavior of the customer account controller to add new actions or modify existing ones. One common requirement is to add a custom action after the forgotpasswordpost action in the Mage_Customer_AccountController. However, this can be challenging due to the built-in authentication logic that redirects the user back to the login page.

Understanding the PreDispatch Logic

Before diving into the solution, let’s first understand the preDispatch logic in the Mage_Core_Controller_Front_Action class:

public function preDispatch()
{
    // ...
    if (!$this->getRequest()->isDispatched()) {
        return;
    }

    $action = $this->getRequest()->getActionName();

    if (!preg_match('/^(create|login|logoutSuccess|forgotpassword|forgotpasswordpost|confirm)/i', $action)) {
        // ...
    } else {
        $this->_getSession()->setNoReferer(true);
    }
}

The preDispatch method checks the current action and authenticates the user if it doesn’t match one of the specified actions. If authentication fails, it sets a flag to redirect the user to the login page.

The Problem with Extending the PreDispatch Logic

When you try to add a new action (e.g., newactionhere) to the preDispatch logic, you face a redirection issue:

public function preDispatch()
{
    // ...
    parent::preDispatch();

    if (!$this->getRequest()->isDispatched()) {
        return;
    }

    $action = $this->getRequest()->getActionName();
    if (!preg_match('/^(create|login|logoutSuccess|forgotpassword|forgotpasswordpost|confirm|newactionhere)/i', $action)) {
        // ...
    } else {
        $this->_getSession()->setNoReferer(true);
    }
}

The problem arises when the parent::preDispatch() call is made. This triggers the built-in authentication logic, which redirects the user back to the login page because the new action doesn’t match any of the allowed actions.

The Solution: Bypassing the Authentication Logic

To resolve this issue, you can bypass the authentication logic by calling the Mage_Core_Controller_Front_Action’s preDispatch method directly:

public function preDispatch()
{
    $action = $this->getRequest()->getActionName();
    if (!preg_match('/^(create|login|logoutSuccess|forgotpassword|forgotpasswordpost|confirm)/i', $action)) {
        Mage_Core_Controller_Front_Action::preDispatch();
    }
}

By calling Mage_Core_Controller_Front_Action::preDispatch() without the parent call, you avoid triggering the built-in authentication logic. This ensures that the new action can be executed without being redirected to the login page.

Best Practices for Extending Magento Controllers

When extending Magento controllers, it’s essential to consider the following best practices:

  1. Avoid Direct Modifications: Instead of modifying core files directly, use Magento’s extension mechanism by creating a custom module.
  2. Override Methods: Use the Mage_Core_Model_Resource layer and resourceModel attributes to override methods instead of modifying them directly.
  3. Follow Naming Conventions: Adhere to Magento’s naming conventions for files and classes to maintain consistency.

By following these best practices, you can ensure a more stable and maintainable system that avoids potential conflicts with future Magento updates.

Conclusion

In this blog post, we discussed the challenges of extending the Mage_Customer_AccountController for custom forgot password actions. By understanding the preDispatch logic and bypassing the authentication redirect, you can successfully add new actions to the controller without being redirected to the login page.

Remember that extending Magento controllers requires careful consideration of best practices to maintain a clean and organized codebase. Always strive to use Magento’s built-in extension mechanisms whenever possible.

If you found this solution helpful or would like to learn more about Magento development, feel free to explore our Magento Development Services at Laravel Company. Our team of expert developers is ready to assist you with any Magento-related challenges you may face.

Cache Security Customers Errors

Our network