Magento Customer Login – Perform Action After Successful Login

magento-1.8magento-1.9

I am creating a module in which I want to check some condition after customer successfully login, if condition is true then customer login otherwise not.

I know two ways of doing this :

  1. Overriding AccountController
  2. With Magento event.

My query are:

  1. which is the best way?
  2. Is there any event with which I can full fill my requirement?

Or if there is other best way of doing this, please recommend.

Best Answer

Best practice of apply hook in magento to add your any extra efforts or customization so always i would suggest to use Magento Event

below is example code which you can implement to achieve your functionality

Use the event customer_login:

<customer_login>
    <observers>
        <yourobservername>
            <type>model</type>
            <class>yourmodule/path_to_class</class>
            <method>customerLogin</method>
        </yourobservername>
    </observers>
</customer_login>

Your observer class would look like this:

class YourCompany_YourModule_Model_Observer
{
    public function customerLogin($observer)
    {
        $customer = $observer->getCustomer();
    }
}

hope this will sure help you.