1 Reply Latest reply on Jan 5, 2009 1:46 PM by Susanne Jarl

    Authenticator logout

    gopi balagala Newbie
      Hi
          When the user logs in, I have set the status for that user in Data base as 1, When user logs out, I have to set the status 0.

           I am facing a Problem on calling a method in Authenticator logout, when I click logout button in the interface,

           The code is below....

      menu.xhtml
      -------------

      <h:panelGrid columns="1">
      <s:link view="/login/logout.xhtml"  action="#{identity.logout}" value="Logout"  rendered="#{identity.loggedIn}" style="#{linkLnF.getLinkSettings(skinBean.skin)}"/>
      </h:panelGrid>


      ------------------------


      components.xhtml
      ------------------------

      <event type="org.jboss.seam.loggedOut">
         <action  execute="#{authenticator.logout}"/>
      </event>

      ------------------------

      Authenticator.java
      ------------------------
      public void logout() {
                
                
      try {
               
      UpdateUserDetails uud = new UpdateUserDetails();

      User u=(User)Contexts.getSessionContext().get("authenticatedUser");

      System.out.println("--------Enter logout--------"+u.getStatus());
      uud.resetStatus(u.getId());
      System.out.println("******logout status******" + u.getStatus());

      log.info("User Logged Out #0", identity.getUsername());
      log.info("Inserting Logout Details for Audit Trial Purpose");
      Contexts.getSessionContext().remove("userFullName");
      Contexts.getSessionContext().remove("lastLoginDate");
      Contexts.getSessionContext().remove("userDetails");
      AuditTrial auditTrial = new AuditTrial();
      auditTrial.setMessage(AuditTrialConstants.LOGGED_OUT);
      auditTrial.setUserId(identity.getUsername());
      Calendar cal = java.util.GregorianCalendar.getInstance();
      auditTrial.setDateOfMessage(cal.getTime());
      auditTrial.setIpAddress(((HttpServletRequest) FacesContext
      .getCurrentInstance().getExternalContext().getRequest())
      .getRemoteAddr());
      AuditTrialController auditTrialController = new AuditTrialController();
      auditTrialController.setAuditMessage(auditTrial);
      } catch (Exception e) {
      log
      .info("An Excpetion Occurred while procesing logout, possible causes can be database not connected or most possibly it is because,"
      + "someone clicked on logout link twice, In this case Ignore this error");
                
                }


      ----------------


      UpdateuserDetails.java
      --------------------------

      public void resetStatus(Long userId) {
      System.out.println("user logout details are:"+users.getStatus());
      userList = (List<User>) createQuery(
      "select users from meweUser users where users.id=:id")
      .setParameter("id", userId).getResultList();
      if (userList.size() == 1) {
      users = userList.get(0);
      if (users.getStatus() == 1) {
      users.setStatus(0);
      }
      }
      users = merge(users);
           }
           
      -------------------------------------


      Please help me


      Thank you.