Reputation: 1753
I have built a site that when a user fills in a form correctly he is redirected to a confirmation page that has the url mySite.com\A\confirmation.
I want to be able to redirect the user to a different page If he enters that url "mySite.com\A\confirmation" himself
What is the best way of achieving this (i was hoping something more elegant then keeping state of each user)
Upvotes: 5
Views: 823
Reputation: 16439
It won't be simple, as you may find lots of edge cases.
When you do a redirect, Play sends a 303 HTTP code and the browser does a new GET request against the URL. You could try to add a parameter to check, but then the user could add that to the navigation bar and the request will work.
Also, you would be violating Idempotence in GET. Not a good thing to do, as browsers may rely on it.
Better add a check in the same page and if the form has not been submitted, just show a message or throw a 404 error (not found).
Upvotes: 2
Reputation: 2434
You could put a token in the flash scope and redirect to mySite.com\A\confirmation
If the token is not there redirect him to another page, otherwise display the page and keep the token in the flash scope. If you keep the token in the flash scope, the user will be able to reload the page without being redirected.
Upvotes: 2
Reputation: 559
Possible simple solutions:
Upvotes: 4