Reputation: 113
I´m having a problem redirecting from a play! form. I think the problem lies in how I´m handling the routes. The idea is that a user should be able to go to dashboard.html either by going first through index.hmtl using login from with a secruity key, or by typing directly in a valid path containing an access_token (using a qr-code redirection)
What I´m trying to do is as follows:
Here is my form (located in index.html):
<form action="@{Dashboard.authenticate()}" method="POST" name="login">
<input name="key" type="password" maxlength="128" value="${flash.key}">
<input class="button" id="btnLogin" type="submit" value="Login">
</form>
public static void dashboard(String access_token) {
/*
...some code
*/
render(username);
}
public static void authenticate(String key) {
/*
...some code
*/
dashboard(access_token);
}
Here is my route file:
# Home page
GET / Application.index
POST /dashboard Dashboard.authenticate
GET /dashboard Dashboard.dashboard
The dashboard route works fine if I call directly upon dashboard(String access_token) through an URL like: http://localhost:9000/dashboard?access_token=0000 But if i try to login using the login form that calls upon authenticate(String key) I get this URL http://localhost:9000/dashboard?access_token&key=1234 where key is the var being sent to the auth()function. Clearly my fault lies with the routes, but I have tried and tested the logic and I am 100% certain it is sound. I´m using Play 1.2.4 I have spent two days on this problem and would be most grateful for any suggestions.
Upvotes: 3
Views: 1732
Reputation: 113
Problem Solved!
What I forgot to mention...oops was that I am also using jQuery Mobile and the problem had to do with Play! routing being overriden my jQuery Mobile page routing.
I disabled the routing by adding the following script:
$(document).bind("mobileinit", function(){
$.mobile.ajaxEnabled = false;
$.mobile.linkBindingEnabled = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
$.mobile.changePage.defaults.changeHash = false;
})
Using instructions on the jQuery website: http://jquerymobile.com/test/docs/api/globalconfig.html I implemented the above but the script needs to referenced in the .hmtml header in the following order:
<script src="jquery.js"></script>
<script src="custom-scripting.js"></script>
<script src="jquery-mobile.js"></script>
Upvotes: 0
Reputation: 16439
The Java code seems fine. Just in case, have you tried to change the routes file to:
# Home page
GET / Application.index
GET /dashboard Dashboard.dashboard
POST /dashboard Dashboard.authenticate
moving the GET before the POST (order matters, this should fix it if there is a Play bug on that section).
Another option is to simply rename the POST route, to fix the issue if it's caused by both routes having the same 'path'.
# Home page
GET / Application.index
GET /dashboard Dashboard.dashboard
POST /dashboard/auth Dashboard.authenticate
Upvotes: 1
Reputation: 33175
That actually seems like a bug. Maybe try
redirect("/dashboard?access_token="+access_token);
instead of
dashboard(access_token);
Upvotes: 1