title: event declared after login in liferay
body: <p>I work  with liferay 5.2  and tomcat 6</p>
  
  <p>I want to save the idportal  and date login  when the user connect to my application which</p>
  
  <p>is depolyed in liferay</p>
  
  <p>I should find the event that is responsible of login</p>
  
  <p>I alreay used a code which will make an update after this event :<strong>onAfterCreate</strong></p>
  
  <pre><code>import com.liferay.portal.model.User;
  .........
  ........
   public void onAfterCreate(User user)
      throws ModelListenerException
    {
      System.out.println("-------------- User Creation::" + user.getScreenName());
      try
      {
        Employee employee = getEmployee(user.getScreenName());
  
        if (employee != null)
          updateEmployee(employee, user, false);
        else
          updateEmployee(new Employee(), user, true);
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
  </code></pre>
  
  <p>so I should use same code like the previous code </p>
  
  <p>the idportal is :<strong>user.getScreenName()</strong></p>
  
  <p>date login I think is <strong>user.getLastLoginDate()</strong></p>
  
  <p>but I didn't find the event which will be decalared after login</p>
  
  <p><strong>Updated</strong> :</p>
  
  <p>I followed yours steps</p>
  
  <p>in liferay-hook.xml I add this code :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_1_0.dtd"&gt;
  
  &lt;hook&gt;
      &lt;portal-properties&gt;portal.properties&lt;/portal-properties&gt;
  &lt;/hook&gt;
  </code></pre>
  
  <p>and in portal.properties  I add </p>
  
  <pre><code>login.events.post=com.liferay.hooks.user.LoginPostAction
  </code></pre>
  
  <p>and I create java class :  LoginPostAction.java</p>
  
  <pre><code>package com.liferay.hooks.user;
  
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import com.liferay.portal.kernel.events.Action;
  import com.liferay.portal.kernel.events.ActionException;
  
  
  
  public class LoginPostAction  
  
  {
  
      public void run(HttpServletRequest request, HttpServletResponse response)
              throws ActionException {
  
          System.out.println("  the user is connected ");
      }
  
  
  
  }
  </code></pre>
  
  <p>in this example the import  import com.liferay.portal.kernel.events.Action;  is unused</p>
  
  <p>as you see I want with this code to display message after login </p>
  
  <p>but when I deploy this example I have this error :</p>
  
  <pre><code>Caused by: java.lang.ClassCastException: com.liferay.hooks.user.LoginPostAction cannot be cast to com.liferay.portal.kernel.events.Action
      at com.liferay.portal.deploy.hot.HookHotDeployListener.initEvent(HookHotDeployListener.java:591)
      at com.liferay.portal.deploy.hot.HookHotDeployListener.initEvents(HookHotDeployListener.java:643)
      at com.liferay.portal.deploy.hot.HookHotDeployListener.doInvokeDeploy(HookHotDeployListener.java:237)
      at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:98)
      ... 31 more
  </code></pre>
  
  <p><strong>updated :</strong></p>
  
  <p>I want to display the ScreenName and login date of user connected ,</p>
  
  <p>I already used this code to display ScreenName <code>user.getScreenName()</code>  and for login date I think that I should use <code>user.getLastLoginDate(</code>)  and I use this import </p>
  
  <pre><code>import com.liferay.portal.model.User;
  </code></pre>
  
  <p>but I didn't find th way to use this code in <strong>the run function</strong></p>
  
  <pre><code>package com.liferay.hooks.user;
  
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import com.liferay.portal.kernel.events.Action;
  import com.liferay.portal.kernel.events.ActionException;
  
  
  
  public class LoginPostAction extends Action
  
  {
  
      public void run(HttpServletRequest request, HttpServletResponse response)
              throws ActionException {
  
          System.out.println("  the user is connected ");
  
       // here I want to display the ScreenName and login date of user connected
      }
  
  
  
  }
  </code></pre>
  
  <p>I try with this code :</p>
  
  <pre><code>package com.liferay.hooks.user;
  
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import com.liferay.portal.kernel.events.Action;
  import com.liferay.portal.kernel.events.ActionException;
  import com.liferay.portal.kernel.util.WebKeys;
  import com.liferay.portal.model.User;
  import com.liferay.portal.theme.ThemeDisplay;
  
  
  
  
  public class LoginPostAction extends Action 
  
  {
  
      public void run(HttpServletRequest request, HttpServletResponse response)
              throws ActionException {
  
          System.out.println("  the user is connected ");
          ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
          User user = themeDisplay.getUser();
          System.out.println("user "+user.getScreenName());
  
      }
  
  
  
  }
  </code></pre>
  
  <p>and I make in portal.properties  this code :</p>
  
  <pre><code>login.events.post=com.liferay.hooks.user.LoginPostAction
  servlet.service.events.post=com.liferay.hooks.user.LoginPostAction
  </code></pre>
  
  <p>but I have this error :</p>
  
  <pre><code>Caused by: java.lang.NullPointerException
      at com.liferay.hooks.user.LoginPostAction.run(LoginPostAction.java:25)
      at com.liferay.portal.kernel.events.InvokerAction.run(InvokerAction.java:52)
      at com.liferay.portal.events.EventsProcessorImpl.processEvent(EventsProcessorImpl.java:92)
  </code></pre>