title: page after login in playframework
body: <p>In my play! app,I have coded the controllers.Security as</p>
  
  <pre><code>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");
     }
  }
  </code></pre>
  
  <p>I have set the routes as</p>
  
  <pre><code>GET     /admin/?              Admin.index
  *       /admin                module:crud
  GET     /                    Application.index
  </code></pre>
  
  <p>When I am on a page say pageX and click on the login link,the login form appears and I am able to login.If I login as admin ,it takes me to the Admin.index() and thereby to Admin/index.html view.So far so good</p>
  
  <p>But,when I am on pageX,and click on login link,I expect to come back to pageX.Instead ,the Application.index() method is called and I am taken to the Application.index.html..
  Is this the expected behaviour?
  What do I have to do to get to pageX after login?</p>
  
  <p>update:</p>
  
  <p>I tried storing the url in flash using the @Before in Security controller</p>
  
  <pre><code>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("/");
      }
        }
     }
  </code></pre>
  
  <p>When I login,I get these terminal output</p>
  
  <pre><code>url=null
  url null  ..go to /
  index()
  </code></pre>
  
  <p>I have put the login/logout links in main.html template which is inherited by all other pages</p>
  
  <pre><code>&lt;div id="main"&gt;
      &lt;div class="auth"&gt;
       &lt;a href="@{Admin.index()}"&gt;Go to Admin Area&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;
       &lt;a href="@{Secure.login()}"&gt;Login&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;
       &lt;a href="@{Secure.logout()}"&gt;Log out&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>