Jump to content

Best way to change controller and action


milesap

Recommended Posts

Hello everyone,

 

I would like to know the best way to approach this problem. I would like my website to check if a user has changed their password within say 4 weeks. If it hasn't been changed, I would like to change the requested controller and action to the change password controller / action.

 

My question therefore is, where should I put this code? In the bootstrap, register a plugin, or another solution? Also, how could I change the controller and action that is displayed to the user if they are required to change their password? Should they be forwarded to the change password controller / action, or can you change the controller / action after dispatch to the change password controller / action? So if a user was on their profile page, but their password is no longer valid I would like to display the change password form instead of their profile.

 

I would prefer the website to check if the password has expired for every page request, and not just during login. I know this is less efficient, however in the future I would like to use this same concept to check for other conditions which may change while the user is logged in.

 

Any help would be much appreciated!

 

  • 2 weeks later...

I'd write a plugin and overwrite the dispatchLoopStartup() method:

 

class My_Controller_Plugin_Password extends Zend_Controller_Plugin_Abstract
{
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
    {
        if(passwordNeedsToBeChanged())
        {
            $request->setControllerName('auth');
            $request->setActionName('password');
        }
    } // end dispatchLoopStartup();
} // end My_Controller_Plugin_Password;

 

Note that your plugin does not have to check, if we are in the password change action or not, because dispatchLoopStartup() is not called again after modifying the $request object.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.