3

Is there any events for admin user login and logout in magento?

I found some events for customer login but not for Admin user login

<events>
         <customer_login>
           <observers>
              <scommerce_customer_login><!--User Defined Unique Name-->
                 <class>scommerce_login/observer</class>
                 <method>checkLoginStatus</method>             
              </scommerce_customer_login>
           </observers>
         </customer_login>
      </events>

For how to get the admin users login events?

4 Answers 4

6

Login:

There are one event exit in magento which fire whenever admin user successfully logged in and can get user details from it parameter:

event name: admin_session_user_login_success

See at class: Mage_Admin_Model_Session

  Mage::dispatchEvent('admin_session_user_login_success', array('user' => $user));

Getting loggin user details: $observer->getEvent()->getUser();

Also fire event admin_session_user_login_failed when admin user goes to fail to login

   Mage::dispatchEvent('admin_session_user_login_failed',
        array('user_name' => $username, 'exception' => $e));

Logout:

For Logout cannot find any event. In this can use controller predispatch & Post dispatch event .

As magento doing logout from Mage_Adminhtml_IndexController at logoutAction then use any one of below events

  • controller_action_postdispatch_admin_index_logout
  • controller_postdispatch_admin_index_logout

Event: controller_postdispatch_admin_index_logout is better for this case.

6
  • Is there any events for admin logout/session expires in magento?
    – Naveenbos
    Commented Sep 3, 2015 at 11:21
  • 1
    Use controller_postdispatch_admin_index_logout. For session timeout there is no event because no code gets executed when a user session times out. Commented Sep 3, 2015 at 11:37
  • yes.. On logout Action magento just clear current adminhtml session varible
    – Amit Bera
    Commented Sep 3, 2015 at 11:44
  • forum.azmagento.com/how-to/track-admin-login-records-80679.html May be this link will help some one
    – Naveenbos
    Commented Sep 3, 2015 at 12:42
  • On your link a new event has been define at controller.And by using this your get data
    – Amit Bera
    Commented Sep 3, 2015 at 14:54
2
 <adminhtml>
<events>
            <admin_session_user_login_success>
                <observers>
                    <Ss_Supportticket_model_observer>
                        <!-- The model to be instantiated -->
                        <class>Ss_Supportticket_model_observer</class>
                        <!-- The method of the class to be called -->
                        <method>saveUserLoginSession</method>
                        <!-- The type of class to instantiate -->
                        <type>singleton</type>
                    </Ss_Supportticket_model_observer>
                </observers>
            </admin_session_user_login_success>
            <!-- <controller_action_predispatch> -->
            <controller_action_predispatch_adminhtml_index_logout>
                <observers>
                    <Ss_Supportticket_model_observer>
                        <!-- The model to be instantiated -->
                        <class>Ss_Supportticket_model_observer</class>
                        <!-- The method of the class to be called -->
                        <method>saveUserLogoutSession</method>
                        <!-- The type of class to instantiate -->
                        <type>singleton</type>
                    </Ss_Supportticket_model_observer>
                </observers>
            </controller_action_predispatch_adminhtml_index_logout>
            <!-- </controller_action_predispatch> -->
        </events>
 </adminhtml>
0

In addition if you need an event before the admin login (for example to restrict login even with a correct credentials) - you can use this

  • admin_user_authenticate_before
0

Here is some example code resurrected from this dead link (archive.org) (untested):

<frontend>
   <events>
<!-- Add Observers for customer on frontend
      customer_login
      customer_logout
 -->
      <customer_login>
          <observers>
             <xxx_Various_Model_Observer>
                <type>singleton</type>
                <class>xxx_Various_Model_Observer</class>
                <method>Observecustomerlogin</method>
             </xxx_Various_Model_Observer>
         </observers>
      </customer_login>
      <customer_logout>
          <observers>
             <xxx_Various_Model_Observer>
                <type>singleton</type>
                <class>xxx_Various_Model_Observer</class>
                <method>Observecustomerlogout</method>
             </xxx_Various_Model_Observer>
         </observers>
      </customer_logout>
  </events>
</frontend>
      
<adminhtml>
   <events>
<!-- Add Observers for Admin on admin backend
      admin_session_user_login_success
      admin_session_user_logout
      admin_session_user_login_failed
 -->
      <admin_session_user_login_success>
          <observers>
             <xxx_Various_Model_Observer>
                <type>singleton</type>
                <class>xxx_Various_Model_Observer</class>
                <method>Observeadminlogin</method>
             </xxx_Various_Model_Observer>
         </observers>
      </admin_session_user_login_success>
      <admin_session_user_logout>
          <observers>
             <xxx_Various_Model_Observer>
                <type>singleton</type>
                <class>xxx_Various_Model_Observer</class>
                <method>Observeadminlogout</method>
             </xxx_Various_Model_Observer>
         </observers>
      </admin_session_user_logout>
      <admin_session_user_login_failed>
          <observers>
             <xxx_Various_Model_Observer>
                <type>singleton</type>
                <class>xxx_Various_Model_Observer</class>
                <method>Observeadminloginfailed</method>
             </xxx_Various_Model_Observer>
         </observers>
      </admin_session_user_login_failed> 
  </events>
</adminhtml>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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