joscha / play-authenticate

An authentication plugin for Play Framework 2.x (Java)
http://joscha.github.com/play-authenticate/
Other
807 stars 366 forks source link

Redirect on other URL than index #365

Closed leccyril closed 6 years ago

leccyril commented 6 years ago

Hi thanks for your great tool !

How can we change the redirection URL, for example following the user role we want to redirect on different URL

It is very important for all versions i think it is a missing configuration really nice and mandatory with your tool.

How we can do ?

thank you very much to maintain the only one module authenticate on my favorite framework !

leccyril commented 6 years ago

? nothing ? no one have this specification ?

leccyril commented 6 years ago

thanks a lot !

i have done like this 👍

`public Result doLogin() {
    com.feth.play.module.pa.controllers.Authenticate.noCache(response());
    final Form<MyLogin> filledForm = this.provider.getLoginForm()
            .bindFromRequest();
    if (filledForm.hasErrors()) {
        //flash(Application.FLASH_ERROR_KEY, this.msg.preferred(request()).at("login.error"));  
        // User did not fill everything properly
        return badRequest(login.render(this.auth, this.userProvider, filledForm));
    } else {
        Result result=this.provider.handleLogin(ctx());
        // Everything was filled

        if("/".equals(result.redirectLocation().get())){
            final User localUser = this.userProvider.getUser(session());
            if(localUser.getStringRoles().contains(Role.SMARTCASTER)) {
                result=redirect(controllers.routes.DashboardManagement.viewSmartCasterGeneralDashboard().toString());
            }else {
                result=redirect(controllers.routes.DashboardManagement.viewSupervisorDashboard().toString());
            }
        }
        return result;
    }
}`
leccyril commented 6 years ago

maybe not class, but without response i had to do this... thanks !