0 Replies Latest reply on Oct 1, 2008 1:48 PM by thiagu.m

    How login after successfully register

      Hi every one
      I am working on the login and registration module of my project.
      I need to allow the user to login after successfully register.
      This is my part of code from register session bean component.


         @In
              private TblUser user;

         @PersistenceContext
              private EntityManager em;

         @In
              private Identity identity;

      public void register()
               {
                em.persist(user);

      identity.setUsername(user.getUserName());
                  identity.setPassword(user.getPassword());
                  identity.login();
                
      }


      Here the identity.login() invoke the authenticate method from Authenticator component.
      This is my sample code from  Authenticator.

        @Out(required=false, scope = SESSION)
        private TabUser user;

          @In
          Identity identity;
         
          @PersistenceContext
          private EntityManager em;

      public boolean authenticate()
      {
      try
              {
                  user = (TabUser)em.createQuery("from TabUser where userName = '"+identity.getUsername()+"'").getSingleResult();
                  if(! user.getPassword().equals(identity.getPassword()))
                  {
                       facesMessages.addToControl("password", "Invalid Password");
                      return false;
                  }
              }
              catch(NoResultException ex)
              {
                   facesMessages.addToControl("password", "Invalid Username or Password");
                  return false;
              }
              return true;
      }


      Here I face the problem is I cant login after successfully register.
      It throws NoResultException exception.
      If I try to login manually , it allow me to login.
      I think the problem is EntityManager not getting flush after persist the user data into Tbluser table.
      I try with em.flush() after persist the user data.
      Still I got the same problem.
      Any help to resole my problem