1

In one of my project, there is requirement of redirect the customer to his/her account to dashboard for changing the password even after click of any links. Actually the customer password is being expired after 30 days.

So, customer can login with the old password even after 30 days but he/she can't browse any thing without changing his/her password.

So, problem is how can we redirect customer to the customer account dashboard change password screen after login and even after click of any links.

Any suggestions on fixing the issue?

  • Thank you murtuza for Formatting changes. I will keep in mind from the next time. Thank you again.. – Pawan Shukla May 31 '16 at 12:40
4

For this you need to use an observer which gets called on the controller_action_predispatch event and check if the customer is logged in or not and if customer is logged in check for your password expiration condition and redirect to customers dashboard.

you can use the following files for your reference.

1) app\etc\modules\TutsPlus_Demo.xml

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <modules>
        <TutsPlus_Demo>
            <active>true</active>
            <codePool>local</codePool>
        </TutsPlus_Demo>
    </modules>
</config>

2) app\code\local\TutsPlus\Demo\etc\config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <global>
        <models>
            <tutsplus_demo>
                <class>TutsPlus_Demo_Model</class>
            </tutsplus_demo>
        </models>
    </global>
    <frontend>
        <events>
            <controller_action_predispatch>
                <observers>
                    <tutsplus_demo>
                        <type>model</type>
                        <class>tutsplus_demo/observer</class>
                        <method>checkLogin</method>
                    </tutsplus_demo>
                </observers>
            </controller_action_predispatch>
        </events>
    </frontend>
</config>

3) app\code\local\TutsPlus\Demo\Model\Observer.php

<?php

class TutsPlus_Demo_Model_Observer
{
    public function checkLogin(Varien_Event_Observer $observer)
    {
        $controller = strtolower(Mage::app()->getRequest()->getControllerName());
        if(Mage::helper('customer')->isLoggedIn()){
            if ($controller == 'account') {
                return $this; //if in allowed actions do nothing.
            } else {
                //Your password expiration code goes here
                Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account/index'));
            }
        }
        return $this;
    }
}

Hope this will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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