rails 3 cookies - cookies

I have a simple app where users type in stuff in a text filed to get various results. I would like a feature where if a user enters something and then closes the browser tab, the next time they come, I can show them their previous/recent searches. This will persist even if they close the whole browser and open it again.
I believe this can be done by help of cookies. Are there some good rails3 gems for using cookies or any simple tutorial that could guide me in a direction?

http://railstutorial.org/chapters/sign-in-sign-out#sec:remember_me
This is a great book to get you started with rails3. (I would recommend to read it from the beginning)
In the link above, listing 9.12 gives you a good explanation about cookies.

Store the info in the session object:
session[:user_entry] = the_user_entry
http://guides.rubyonrails.org/action_controller_overview.html#session

Related

CookieAuthenticator restlet

I have built some RESTful api's with REstlet 2.3.4. I've been using HTTP_BASIC which let the browser prompt for credentials but it's time for a proper login form. I figure the easiest way to implement this is CookieAuthenticator. I can't find full working examples on github/google. I am sure i'm over looking them can someone provide a working example implementing CookieAuthenticator in Restlet?
I did get this to work after all. I have a longer answer here with some code examples. First, i was missing the fact that CookieAuthenticator is a filter and HAS the logic to handle login and logout. You need to create EMPTY ServerResources with a method annotated with #Post that has nothing in the body. Second, extend CookieAuthenticator and overwrite isLoggingIn(..) and isLoggingOut(..) with the code found in the link.
Cheers,
-ray

Read AICC Server response in cross domain implementation

I am currently trying to develop a web activity that a client would like to track via their Learning Management System. Their LMS uses the AICC standard (HACP binding), and they keep the actual learning objects on a separate content repository.
Right now I'm struggling with the types of communication between the LMS and the "course" given that they sit on two different servers. I'm able to retreive the sessionId and the aicc_url from the URL string when the course launches, and I can successfully post values to the aicc_url on the LMS.
The difficulty is that I can not read and parse the return response from the LMS (which is formatted as plain text). AICC stipulates that the course start with posting a "getParam" command to the aicc_url with the session id in order to retrieve information like completion status, bookmarking information from previous sessions, user ID information, etc, all of which I need.
I have tried three different approaches so far:
1 - I started with using jQuery (1.7) and AJAX, which is how I would typically go about a same-server implementation. This returned a "no transport" error on the XMLHttpRequest. After some forum reading, I tried making sure that the ajax call's crossdomain property was set to true, as well as a recommendation to insert $.support.cors = true above the ajax call, neither of which helped.
2 & 3 - I tried using an oldschool frameset with a form in a bottom frame which would submit and refresh with the returned text from the LMS and then reading that via javascript; and then a variation upon that using an iFrame as a target of an actual form with an onload handler to read and parse the contents. Both of these approaches worked in a same-server environment, but fail in the cross-domain environment.
I'm told that all the other courses running off the content repository bookmark as well as track completion, so obviously it is possible to read the return values from the LMS somehow; AICC is pitched frequently as working in cross-server scenarios, so I'm thinking there must be a frequently-used method to doing this in the AICC structure that I am overlooking. My forum searches so far haven't turned up anything that's gotten me much further, so if anyone has any experience in cross-domain AICC implementations I could certainly use recommendations!
The only idea I have left is to try setting up a PHP "relay" form on the same server as the course, and having the front-end page send values to that, and using the PHP to submit those to the LMS, and relay the return text from the LMS to the front-end iframe or ajax call so that it would be perceived as being within the same domain.... I'm not sure if there's a way to solve the issue without going server-side. It seems likely there must be a common solution to this within AICC.
Thanks in advance!
Edits and updates:
For anyone encountering similar problems, I found a few resources that may help explain the problem as well as some alternate solutions.
The first is specific to Plateau, a big player in the LMS industry that was acquired by Successfactors. It's some documentation that provide on setting up a proxy to handle cross-domain content:
http://content.plateausystems.com/ContentIntegration/content/support_files/Cross-domain_Proxlet_Installation.pdf
The second I found was a slide presentation from Successfactors that highlights the challenge of cross-domain content, and illustrates so back-end ideas for resolving it; including the use of reverse proxies. The relevant parts start around slide 21-22 (page 11 in the PDF).
http://www.successfactors.com/static/docs/successconnect/sf/successfactors-content-integration-turley.pdf
Hope that helps anyone else out there trying to resolve the same issues!
The answer in this post may lead you in the right direction:
Best Practice: Legitimate Cross-Site Scripting
I think you are on the right track with setting up a PHP "relay." I think this is similar to choice #1 in the answer from the other post and seems to make most sense with what you described in your question.

WinInet and SessionCookies

Hello and good evening to all.
I have my app that uses InternetSetCookie to create (session) cookies needed for its job. However I want to remove the cookie named for ex. 'badcookie' after each request via
InternetSetCookie("http://www.domain.com", "badcookie", "");
and
InternetSetCookie("http://www.domain.com", NULL, "badcookie=")
but...in best case it will send cookie w/o any value and thats that.
My question is how to completly remove this cookie?
(No, I dont want to make them permanent and call cleanup() 10 times, maybe I would create thread for each request but its akward if I do it)
InternetSetCookie("http://domain.com", NULL, "badcookie=bye; expires = Sat,01-Jan-1970 00:00:00 GMT");
This removed the complete txt file with some other cookies inside. Before I was using www.domain.com and I saw that it was problem... now I face same issue as the link you posted (lossing more cookies) but my question is answered now.
PS This works with session cookies too.
My answer isn't 100% complete, but maybe it's a start. I'd suggest setting the expiration of the cookie to be in the past, as this will force the client to clear the cookie. I'm not familiar with WinINET syntax, so maybe someone has a better answer. I'm more of an ASP.NET person - but this article seems to suggest how to expire the cookie.
Based on gaor's response to my initial comment, sounds like there's still a little more work to do to completely fix this. But hopefully this helps and gets someone pointed in the right direction.
Hope this helps!

How can I retrieve all comments on a Facebook post using the php SDK?

I'm building an app which allows users to post articles to their facebook wall. When an article is posted, I retrieve the post id and store that in the database along with the rest of the article details. Now I want to be able to show the comments made on that post when someone views the article in my site; I would also like to allow users to add comments to the post from my site.
I know that the user is always logged into Facebook when they are viewing the article, as the system checks for that earlier on.
I've been using the PHP SDK, and thought all I had to do was something like:
$post_comments = $facebook->api('/' . $post_id . '/comments');
However, when I do this, I get the following error:
Fatal error: Uncaught GraphMethodException: Unsupported get request. thrown in /APP_PATH/facebook/src/facebook.php on line 560
I really don't have much of a clue what I'm doing here, to be honest, as I'm very new to the Facebook Graph API, and I can't seem to find a lot of documentation on it.
Can anyone tell me what I should be doing here, or point me to some documentation I could read about it?
Thanks!
It should work.
Here is the code I am using which is working for me.
$comments = $facebook->api($postid . '/comments');
Make sure your postid is a valid one.
Alternatively, you can directly type that url in browser to get details like this
https://graph.facebook.com/<postedid>/comments
Please refer this link for further reference
http://developers.facebook.com/docs/reference/api/Comment/
I don't know what your PHP library is doing, but you can actually access comments by reading graph.facebook.com/<post_id>/comments. Indeed, try with this one from the doc.
Are your sure of your post id? Try to call the buggy function with 19292868552_118464504835613 as post id. It has to work.

Facebook Group invite via Graph API

I about to built a little online game in Action Script 3. At the moment everything is working pretty fine and there is just one thing left to do that makes me going crazy. After every Level of the Game the user should notified about his success and in case that the success was good enough, the user should be invited to a facebook group. At the Moment i have got an Facebook App, Authentification and Authorisation are working and what still is to manage is the invitation itself.
Does anybody know if there is a way to make this happen, and if so, how could it be done? Thanks a lot for a reply!
greetings!
So, after having a nice day of »facebook api investigation« i would sum up the things i found out:
I'm quite sure that there is no way to make an group invitation via the graph api. The best result i could reach was an Error that told me: »requires the manage_groups permission«.
Consequently I added this permission to the login method and »tada«: the app didn't work anymore, just told me that there is an error with the app and I should try later again.
The code for getting this great message looked like this:
FB.api( "//members","POST", { name : "user name" }, function( response ){
//the great error appears here in the response
} );
I also was looking for something in the facebook.connect api but could not find something related to the problem i tried to solve.
If there is anybody who knows something better to try, i would very interested.
Greeting Philipp
Looks like "manage_groups" is not available to the public, (yet?). I'm following this and this discussion about it, as "manage_groups" seems to be required to invite a user to a group, but is not listed in the Facebook reference of extended permissions.