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 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:


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.


It is good idea to use magento event.

In some time you cannot login from only AccountController also from another controller,That times you need rewrite those controlller . It it little of rework for every loggin Action.

Event: Use event customer_login.This event does not depends on Controller and etc.

See how to use this event Can't set an observer on customer_login

  • Thanks @amit, can you explain me hoe customer_login works – Deepak Mankotia Jun 12 '15 at 5:21
  • bascially we have done the loggin by using $CustomerSession->login('usernname','password') and in loggin customer magento is authenticate customer as set Customer in current session.... You can see the code at Mage_Customer_Model_Session function loggin and setCustomerAsLoggedIn function – Amit Bera Jun 12 '15 at 5:26
  • have you understood... that... – Amit Bera Jun 12 '15 at 5:42
  • yes, i'm implementing this in my module....i will update you with the result – Deepak Mankotia Jun 12 '15 at 5:50

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.