问题
I have integrated the Play-Authenticate module in my Play 2.0.4 project. There are two views to my project, a conventional web view and a mobile view. When the application logs out it just returns to the index page. In the routes table I see that the logout functionality points towards this:
GET /logout com.feth.play.module.pa.controllers.Authenticate.logout
Which looks like this in the module code:
public static Result logout() {
noCache(response());
return PlayAuthenticate.logout(session());
}
The way the application works is there is a main.scala.html file with the css/js links that the web application needs and a mobile_main.scala.html page with the css/js that the contents of the mobile templates use. The problem I am having is that when I sign out of the application (either mobile or web) I get redirected to the index of the web application - index.scala.html. Is there anyway to change this so that I can be directed to the mobile index page when appropriate?
Thanks
Edit: This also applies to the page the application returns to after a successful login.
Ok after looking a bit further I traced the problem back to Global.java. I think I need to change the methods below to solve my problem. So that I can load a different page depending on an argument passed perhaps.
@Override
public Call login() {
// Your login page
return routes.Application.login();
}
@Override
public Call afterAuth() {
// The user will be redirected to this page after authentication
// if no original URL was saved
return routes.Application.index();
}
@Override
public Call afterLogout() {
return routes.Application.index();
}
回答1:
One of the way is to save your state in the session, for example you can have two states: mobile session
and web session
and then verify this in condition before redirecting
if mobile session then redirect mobile index else redirect index
来源:https://stackoverflow.com/questions/16254135/play-authenticate-logout-redirect