Search code examples
playframeworksecuresocial

SecureSocial login after signup


I'm using Play Framework 2.1 with SecureSocial.
I have my own templates, UserService, and UsernamePasswordProvider/FacebookProvider.

I dont use SecureSocial to register my users, but I use it to login and handle sessions. How can I make people be logged in after registration, so in my Java code ?

I tried to use Authenticator.create(...)

securesocial.core.Authenticator.create(Scala.orNull(securesocial.core.UserService.find(new securesocial.core.UserId(newUser.getId(),"wimhauserpass"))));

but I cant use UserService.find(), it tells me it must be static ...

I'm gonna implement another Provider dedicated to retrieve credentials from the RegisterForm, and call

securesocial.controllers.ProviderController.authenticate("userpassregister");

Any better idea ?

Thanks


Solution

  • If I understood you correctly you have a custom signup controller and after successful signup the user shall be logged in.

    We also had this case in a play2 java app with securesocial, and our CustomRegistrationController.handleSignUp method looks s.th. like this:

    public Result handleSignUp(final String token) {
        // verify token, validate form, fill user from form etc.
        ...
    
        // save user in userService, delete token
        userService.doSave(user);
        userService.doDeleteToken(token);
    
        // login user
        final Either<Error, Authenticator> result = Authenticator.create(user);
        if (result.isLeft()) {
            // add some msg to flash, redirect to login
            ...
            return redirect(RoutesHelper.login());
        }
    
        // Add the auth cookie to response
        final play.api.mvc.Cookie authCookie = result.right().get().toCookie();
        response().setCookie(authCookie.name(), authCookie.value(),
            (Integer)Scala.orNull(authCookie.maxAge()), authCookie.path(),
            Scala.orNull(authCookie.domain()), authCookie.secure(), authCookie.httpOnly());
    
        // Add some success message
        ...
        return redirect(routes.UserSignUpController.signUpConfirmation());
    }
    

    I hope this answers your question.