Redirect with URL fragment with Play framework 2 - scala

How can I add an URL fragment (#xyz) to a link created by the Redirect method?
I want something like this:
Redirect(routes.Comment.get(itemId) + "#xyz")

You can get the url form the route using .url (which contains a relative url). Redirect needs two parameters to accept a string to redirect to
so, Redirect(routes.Comment.get(itemId).url + "#xyz", SEE_OTHER) should work
Edited when I realized Redirect() takes a Call and not a string

With Play Framework 2.4 is possible do this:
Redirect(routes.Comment.get(itemId).withFragment("#xyz").toString)

Related

Querystring inside Querystring

I have a problem on my webpage with an querystring I have to pass inside a querystring.
The main querystring is a cookie checker. And inside this I need to pass a second URL that contain also a querystring with &. The second querystring is now broken after website is parsed:
http://www.myurl.com/check_affiliate_cookie_exist.jsp?contractId=3241248&referrer=*&foundString=linkok&notFoundString=https%3A%2F%2Fwww.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WZ7CHZVKKLNQW"
When I now click on the second link, it is broken at & and the second part of this "sub querystring" is broken.
Any idea how to deal with this?
You need to escape, you can use js for example
var url = mainUrl + encodeURIComponent(secondUrl);
You should use rawurlencode if you're using PHP. You will then need to decode the URL using rawurldecode. If you're not using PHP, then check for equivalent functions in your scripting language.
Hope this helps!

Yii - formatting GET url created by form submisson

Can i change the URL format generated by a Yii form submisson?
eg. my url using the get method will look like:
domain/search/new?Search[field_1]=1&Search[field_2]=2&Search[field_3]=3
can i make it look like:
domain/search/new/1/2/3 or
domain/search/new/field_1:1/field_2:2/field_3:3 or
domain/search/new/field_1/1/field_2/2/field_3/3
Not if you let the browser submit the form normally.
On the other hand, if you use jQuery to prevent the form submission and make a custom AJAX request (or even point the browser to another URL) instead then you can do anything you like.

Zend framework - duplication in translated url

I have these URLs
cz/kontroler/akce
en/controller/action
Is used transatable route and works it like charm. But problem is, that when you will write
cz/controller/akce
it works as well.
In generally when you have
cz/something-in-czech
en/something-in-english
which route to someController, will be works still
cz/some
en/some
because it is really name of controller.
How solve this duplicity content issue?
You can create a plugin that uses a preDispatch method. Before the request is executed, you can analyze the url requested and check if the requested language match the language of the params in the url (I mean controller and action). If not, you can redirect the user to the url that is in accord to the given language (basically you'll translate the controller and the action and then redirect the user to the right url).

How do I redirect the user to another page in Play Framework?

I need to direct the user to another URL after the server has received some form data. How can I redirect the user in Play Framework?
I have tried with:
val url = "http://127.0.0.1:9000/user/" + user.id + "/" + user.name
response.setHeader("Location", url)
But the user is not redirected. With PHP I can do this using:
header('Location: http://127.0.0.1:9000/user/'.user->id.'/'.user->name);
I have tried to use Action(MyController.myMethod) but then is not the "preferred" URL used. How do I set a redirect header using Play Framework?
Why not simply use?
redirect("http://www.zenexity.fr");
You need to use the reverse router, something similar to this should work:
Redirect(mypackage.myitems.routes.MyController.myItem(myItemId))
The parameter is optional.

Is it possible to pass parameters to the callback URL of a FB app which is accessed through a tab?

I have this facebook application which adds a custom tab to fan pages. You access the tab by an URL like:
http://www.facebook.com/pages/PAGE-NAME-HERE/PAGE-ID?v=APP-ID
I want to be able to add some extra get parameters to that URL, but it seems they don't get passed correctly because facebook is filtering them. Is there a way to pass those parameters? Even not via GET but some other kind of technique.
If you want to pass multiple querystring params though the app_data param, you can urlencode it.
All querystring params that need to propagate through a Facebook tab should be url-encoded in the app_data var.
In other words, the "&" and the "=" need to be url-encoded (especially if passing more than one param).
Examples
GOOD TAB URL (this passes all 3 params):
https://www.facebook.com/pages/yourpagename/56789?sk=app_12345&app_data=var1%3D123456789%26anothervar%3Drawr%26athird%3Dmeow
In the app_data from this signed request, I got this value: var1=123456789&anothervar=rawr&athird=meow
BAD TAB URL (this passes only the first param through the signed_request):
https://www.facebook.com/pages/yourpagename/12345?sk=app_56789&app_data=var1=123456789&anothervar=rawr&athird=meow
In the app_data from this signed request, I ONLY got this value: var1=123456789 (Facebook dropped the rest)
You can even give your media team instructions like this =)
Media team,
Here is an online utility to urlencode the querysting data you want to
embed in the app_data param: http://meyerweb.com/eric/tools/dencoder/
Base Url: https://www.facebook.com/pages/yourpagename/12345?sk=app_56789&app_data=
Steps:
Go to http://meyerweb.com/eric/tools/dencoder/
Type var1=123456789&anothervar=rawr&athird=meow in the box
Hit the Encode button
You’ll get var1%3D123456789%26anothervar%3Drawr%26athird%3Dmeow which becomes your app_data param. Append that to the baseUrl noted above like this:
https://www.facebook.com/pages/yourpagename/12345?sk=app_56789&app_data=var1%3D123456789%26anothervar%3Drawr%26athird%3Dmeow (this is the URL with the tracking params for the [banner ad] [online media] [etc])
p.s. Querystring params in non-tab pages are handled fine (https://apps.facebook.com/yourappname/Canvas.aspx?var1=123456789&anothervar=rawr&athird=meow does not strip out qs params like what happens in the Tab, for example).
You must pass the app_data parameter in the URL:
http://facebook.com/pages/:page_id/:page_name?sk=app_:app_id&app_data=my_data
You will then access it through the signed_request param. For instance with Ruby and RestGraph:
user = RestGraph.new.parse_signed_request(params[:signed_request)
data = user['app_data'] # => "my_data"
Appending app_data worked for me.
http://www.facebook.com/pages/MyPage/11111111111111?sk=app_22222222229&app_data=foo_bar
Then retrieve signed request using PHP SDK (in my case). app_data is then available in the assoc. array returned.
I was wondering the same, in my case I had needed to pass a parameter "from" to identify if user was using mobile form or web form to login. My app use Spring Security. The way I was able to do that was creating my own SocialAuthenticationFilter:
1) Add a (hidden in my case) parameter to your login form ("from" in this example).
2) Get the right SocialAuthenticationFilter.java source (in accordance with your Spring version).
3) Create your MySocialAuthenticationFilter using it.
4) In method:
getRequestedProviderId(HttpServletRequest request) is where you can
grab your parameter:
private String getRequestedProviderId(HttpServletRequest request) {
String f = request.getParameter("from");
if(f!=null) {
final String dbValue = request.getParameter("from");
request.getSession().setAttribute("from", dbValue);
}
...
And thats all. In this way after a successful authentication you will be able to recover from session your parameter.
Be aware this method is called several times during OAuth exchanging, and when it is called from the authentication provider (Facebook for example) the parameter will be null. That is the reason to check the value before save in session in order to avoid delete your right value.
I answer myself by saying this is not possible.