How to fetch and display the last login time for the logged in user in portal theme

 Sometimes it's an explicit requirement of the website to display the last login time for the logged in users. By default Websphere portal logs the user's' last login time in portal DB itself and we can easily fetch that with the help of PUMA API.
// For new PUMA user object
com.ibm.portal.um.User user = pumaProfile.getCurrentUser();
UserImpl userImpl = (UserImpl)user;
userImpl.getDescriptor().getLastLoginTime();
// For old PUMA user object
com.ibm.wps.puma.User oldUser = (com.ibm.wps.puma.User)request.getUser();
oldUser.getDescriptor().getLastLoginTime();

You can use the same code directly in theme's default.jsp or in the doView() method of the portlet by importing corresponding packages

1 comment:

  1. Hi Vamsee,
    I am trying to figure out where does the UserImpl class comes from, do you have a fully classified name for this class.

    ReplyDelete