2 Replies Latest reply on Sep 5, 2008 8:40 PM by vk101

    Automatic login upon successful user registration

      What’s the proper way to implement functionality where a successfully-registered user is immediately logged in? When directly attempting to log in, everything works as expected. However, when attempting to automatically log someone in upon registration of their new user account, it fails.

      At the end of my registration method (at the point where registration is successful), I call identity.login() whose underlying authenticate-method uses EntityManager to search for whether a user with the supplied username/password exists in the database. This search fails, returning no matching user record, even though the user has successfully registered and their user record has been physically written to the database!

      Before trying that search, I tried calling EntityManager’s clear() and flush() methods, but no luck. I didn’t expect that to work anyways, because the record has already been written to the database at this point - why can’t this search see that the record already exists?

      What’s the proper way to implement such functionality? Thanks.

        • 1. Re: Automatic login upon successful user registration

          Create your logic in the POJO and when it succeeds use the variable/flag saying that the registration succeeds in the pages.xml to redirect to the page you want.

          • 2. Re: Automatic login upon successful user registration

            I'd prefer not to have a successful-registration flag, for example, in the registration POJO just for the sake of getting around this issue - unless that is how you'd want to do login-after-registration even if I weren't getting the issue from my original post - is it?

            Using the way I tried, I have a login method as well as a registration method which simply calls the login method at the end - simple and clean, except for the issue I'm facing.

            What's causing this - what do I need to do to the EntityManager instance to see the record that it just wrote to the database?