Page after entering playframework

In my game! app, I encoded the controllers. Safety like

class Security extends controllers.Secure.Security {
...
   static void onDisconnected() {       
       Application.index();
   }
   static void onAuthenticated() {
      User user = User.find("byEmail",Security.connected()).first();
      if(user.isAdmin()) {
         Admin.index();
      }else {
          System.out.println("onAuthenticated()::user not admin");
   }
}

I set the routes as

GET     /admin/?              Admin.index
*       /admin                module:crud
GET     /                    Application.index

When I say pageX on the page and click on the login link, the login form appears, and I can log in. If I log in as an administrator, this will lead me to Admin.index () and thereby to Admin / index.html view.So far so good

But, when I am on pageX and click on the login link, I expect to return to pageX. Instead, the Application.index () method is called, and I end up in Application.index.html .. Is this the expected behavior? What do I need to do to go to pageX after logging in?

update:

I tried to save the url in flash using @Before in the security controller

class Security extends controllers.Secure.Security {
   @Before
   static void storeCurrentUrl() {
      System.out.println("storeCurrentUrl()");
      flash.put("url", "GET".equals(request.method) ? request.url : "/");
   }
   static boolean authenticate(String username, String password) {
   ...
   }

   static void onAuthenticated() {
      ...
      String url = flash.get("url");
      System.out.println("url="+url);
      if(!user.isAdmin()) {
         if(url!=null) {
        System.out.println("url not null");
        redirect(url);
     }else {
       System.out.println("url null  ..go to /");
       redirect("/");
    }
      }
   }

,

url=null
url null  ..go to /
index()

/ main.html,

<div id="main">
    <div class="auth">
     <a href="@{Admin.index()}">Go to Admin Area</a><br/><br/>
     <a href="@{Secure.login()}">Login</a><br/><br/>
     <a href="@{Secure.logout()}">Log out</a>
</div>
+5
3

'login()' 'url' flash- :

flash.put("url", "GET".equals(request.method) ? request.url : "/");

URL- .

String url = flash.get("url");
redirect(url); //you may redirect to "/" if url is null
+7

, . Application.index Admin.index, admin.

, , .

. : GET/login?action=Application.something → . , .

0

Play URL-, , .

, url - "onAuthenticated". "redirectToOriginalURL" "url".

static void onAuthenticated() {
    flash.put("url", "GET".equals(request.method) ? request.url : "/");
}
-2

All Articles