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

Change redirect after login #161

Closed jaybytez closed 10 years ago

jaybytez commented 10 years ago

Is there any easy way to change the redirect after login to something other than "/"?

Jay

jaybytez commented 10 years ago

I was able to get around this with some kludge. There doesn't appear to be anyway to change where the doLogin routes too (partially because I am new to Play and cannot find a way to evaluate a Result's path). So I did the following code where I try to cast the response within the doLogin and determine if the path is "/", so that I can redirect them to their profile (as an example). Unless the Result is to another location (like an error happening), I allow that path to continue. Please share if there is a better way:

Results.Redirect redirect = (Results.Redirect)UsernamePasswordAuthProvider.handleLogin(ctx()); if(StringUtils.contains(redirect.getWrappedSimpleResult().toString(), "/)")) { return Application.profile(); } return redirect;

FTraian commented 10 years ago

You can rewirte Global.afterAuth() as explained in https://github.com/joscha/play-authenticate/blob/master/samples/java/Getting%20Started.md

jaybytez commented 10 years ago

Worked like a charm...thanks a ton!

amosjyng commented 10 years ago

Is there a way to dynamically change this to where the user was before he logged in/out?

joscha commented 9 years ago

@amosjyng not out of the box, but you could save that value somewhere and read it in afterAuth

amosjyng commented 9 years ago

@joscha hm, would you recommend putting the session and page into the cache?

joscha commented 9 years ago

@amosjyng the cache is always a bad place once your application is spread throughout multiple nodes and/or gets rebooted, etc. The page could be put in the session I guess as its small enough to do so. As long as the cookie exists, there is a location you can jump back to and when/if the user deletes his/her cookies I think it is fair enough to also not return to that page.