simple_facebook_connect 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/MIT-LICENSE +20 -0
- data/README.md +115 -0
- data/Rakefile +27 -0
- data/VERSION +1 -0
- data/app/controllers/simple_facebook_connect/connect_controller.rb +59 -0
- data/app/views/shared/_facebook_connect_button.html.erb +15 -0
- data/config/simple_facebook_connect_routes.rb +4 -0
- data/generators/simple_facebook_connect_features/simple_facebook_connect_features_generator.rb +14 -0
- data/generators/simple_facebook_connect_features/templates/facebook_auth_getsession.xml +9 -0
- data/generators/simple_facebook_connect_features/templates/facebook_connect.feature +27 -0
- data/generators/simple_facebook_connect_features/templates/facebook_connect_steps.rb +19 -0
- data/generators/simple_facebook_connect_features/templates/facebook_connect_stubs.rb +43 -0
- data/generators/simple_facebook_connect_features/templates/facebook_users_getinfo.xml +119 -0
- data/generators/simple_facebook_connect_migration/simple_facebook_connect_migration_generator.rb +13 -0
- data/generators/simple_facebook_connect_migration/templates/migration.rb +17 -0
- data/init.rb +35 -0
- data/lib/simple_facebook_connect/controller_extension.rb +11 -0
- data/lib/simple_facebook_connect/extensions/routes.rb +13 -0
- data/lib/simple_facebook_connect/parser.rb +163 -0
- data/lib/simple_facebook_connect/service.rb +34 -0
- data/lib/simple_facebook_connect/session.rb +73 -0
- data/lib/simple_facebook_connect/user.rb +28 -0
- data/lib/simple_facebook_connect/user_extension.rb +21 -0
- data/lib/simple_facebook_connect.rb +14 -0
- data/rails/init.rb +1 -0
- data/simple_facebook_connect.gemspec +71 -0
- data/spec/fixtures/facebook.auth.getSession/default.xml +9 -0
- data/spec/fixtures/facebook.users.getInfo/default.xml +119 -0
- data/spec/lib/simple_facebook_connect/parser_spec.rb +12 -0
- data/spec/lib/simple_facebook_connect/user_extension_spec.rb +16 -0
- data/spec/lib/simple_facebook_connect/user_spec.rb +37 -0
- data/spec/spec_helper.rb +30 -0
- metadata +91 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.sqlite3
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
## Simple Facebook Connect
|
2
|
+
|
3
|
+
This plugin adds the ability to sign in/sign up using facebook connect to your Rails application.
|
4
|
+
|
5
|
+
## Disclaimer
|
6
|
+
|
7
|
+
Most of the code here is a direct rip-off of the facebooker gem. We wanted something much simpler than facebooker so we took the code we needed, refactored and changed bits and pieces and here we are.
|
8
|
+
|
9
|
+
## Basic process
|
10
|
+
|
11
|
+
With this plugin you will add the well know facebook connect button to your site. When a visitor clicks on it:
|
12
|
+
|
13
|
+
* she will be redirected to facebook
|
14
|
+
* after signing in at facebook be directed back to your signup page
|
15
|
+
* there she will sign up as usual but without being asked to enter a password
|
16
|
+
* after signing up she will be able to sign into your site by clicking the facebook connect button
|
17
|
+
|
18
|
+
When an existing user of your site clicks the button he will also be able to log in via facebook, given the email address he signed up with at your site is also known to facebook.
|
19
|
+
|
20
|
+
## Set up a facebook application
|
21
|
+
|
22
|
+
For basic application setup see the [facebook developer documentation](http://developers.facebook.com/get_started.php).
|
23
|
+
|
24
|
+
Set the "Canvas Callback URL" to "http://your.server.com/fb/connect" and the "Connect URL" to "http://your.server.com". Write down the API and secret key for later.
|
25
|
+
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
This plugin assumes you have a `User` model with an `email` attribute. It will add some extensions to your `User` model and controllers in order to provide the necessary hooks and calls for facebook to authenticate your users.
|
30
|
+
|
31
|
+
Install the gem:
|
32
|
+
|
33
|
+
sudo gem install upstream-simple_facebook_connect
|
34
|
+
|
35
|
+
Add it as a dependency to your Rails application:
|
36
|
+
|
37
|
+
# environment.rb
|
38
|
+
gem 'upstream-simple_facebook_connect', :source => 'http://gems.github.com'
|
39
|
+
|
40
|
+
Run the migration generator and migrate:
|
41
|
+
|
42
|
+
script/generate simple_facebook_connect_migration
|
43
|
+
rake db:migrate
|
44
|
+
rake db:test:clone
|
45
|
+
|
46
|
+
In the meantime we have created a _RAILS_ROOT/config/simple_facebook_connect.yml_ file in which you should enter your facebook API and secret keys.
|
47
|
+
|
48
|
+
After that add the facebook connect button to your sign up and/or sign in pages. We have prepared a partial for you:
|
49
|
+
|
50
|
+
<%= render :partial => 'shared/facebook_connect_button' %>
|
51
|
+
|
52
|
+
Add this to your signup action (`users/create` in most cases):
|
53
|
+
|
54
|
+
class UsersController < ApplicationController
|
55
|
+
def create
|
56
|
+
@user = # initialize user
|
57
|
+
....
|
58
|
+
@user.fb_uid = facebook_user.uid if facebook_user
|
59
|
+
@user.save
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
Change your signup form to not show any password fields when signing up via facebook:
|
64
|
+
|
65
|
+
<%- unless facebook_user -%>
|
66
|
+
<%= f.password_field :password -%>
|
67
|
+
...
|
68
|
+
<%- end -%>
|
69
|
+
|
70
|
+
Provide a `log_in(user)` method, either in your `ApplicationController` or by subclassing `SimpleFacebookConnect::ConnectController`:
|
71
|
+
|
72
|
+
class AppicationController < ActionController::Base
|
73
|
+
|
74
|
+
...
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def log_in(user)
|
79
|
+
session[:user_id] = user.id # or whatever your app does
|
80
|
+
redirect_to account_path
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
Optional step (well, you really should do this): Generate Cucumber Features:
|
85
|
+
|
86
|
+
script/generate simple_facebook_connect_features
|
87
|
+
|
88
|
+
This will generate a feature, step definitions and fixtures to test the facebook connect integration. You will probably have to adjust those files to fit your app, for example we are using _Machinist_ to generate `User` instances.
|
89
|
+
|
90
|
+
Finally: run the features and by now everything should be green. Congrats.
|
91
|
+
|
92
|
+
## What else
|
93
|
+
|
94
|
+
You can grab some of the facebook profile data (e.g. name, location, picture) when signing up your new users. For a complete list of attributes see `SimpleFacebookConnect::User::FIELDS`. In order to do that you could add a line of code to your signup action:
|
95
|
+
|
96
|
+
class UsersController < ApplicationController
|
97
|
+
def create
|
98
|
+
@user = # initialize user
|
99
|
+
....
|
100
|
+
if facebook_user
|
101
|
+
@user.name = facebook_user.name
|
102
|
+
@user.about_me = facebook_user.about_me
|
103
|
+
end
|
104
|
+
@user.save
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
## Links
|
109
|
+
|
110
|
+
* facebooker: http://facebooker.rubyforge.org/
|
111
|
+
* contact: http://upstream-berlin.com
|
112
|
+
* email: alex [at] upstream-berlin dot com
|
113
|
+
|
114
|
+
|
115
|
+
Copyright (c) 2009 Alexander Lang, Frank Prößdorf, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
Jeweler::Tasks.new do |gem|
|
10
|
+
gem.name = "simple_facebook_connect"
|
11
|
+
gem.summary = %Q{This plugin adds the ability to sign in/sign up using facebook connect to your Rails application.}
|
12
|
+
gem.email = "alex@upstream-berlin.com"
|
13
|
+
gem.homepage = "http://github.com/upstream/simple_facebook_connect"
|
14
|
+
gem.authors = ["Alexander Lang", 'Frank Prößdorf']
|
15
|
+
end
|
16
|
+
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Default: run specs.'
|
22
|
+
task :default => :spec
|
23
|
+
|
24
|
+
desc "Run all specs"
|
25
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
26
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.5
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module SimpleFacebookConnect
|
2
|
+
class ConnectController < ApplicationController
|
3
|
+
|
4
|
+
def authenticate
|
5
|
+
redirect_to new_facebook_session.login_url
|
6
|
+
end
|
7
|
+
|
8
|
+
def connect
|
9
|
+
begin
|
10
|
+
new_facebook_session(params['auth_token'])
|
11
|
+
if facebook_user
|
12
|
+
unless log_in_via_fb_id(facebook_user) || log_in_via_email_hash(facebook_user)
|
13
|
+
redirect_to(signup_path)
|
14
|
+
end
|
15
|
+
else
|
16
|
+
render(:nothing => true)
|
17
|
+
end
|
18
|
+
rescue FacebookApiError => e
|
19
|
+
Rails.logger.warn e.message
|
20
|
+
redirect_to fb_authenticate_path
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def signup_path
|
27
|
+
new_user_path(:fb_user => 1)
|
28
|
+
end
|
29
|
+
|
30
|
+
def new_facebook_session(token = nil)
|
31
|
+
facebook_session = Session.new(SimpleFacebookConnect.api_key, SimpleFacebookConnect.secret_key)
|
32
|
+
if token
|
33
|
+
facebook_session.auth_token = token
|
34
|
+
facebook_session.secure!
|
35
|
+
session[:facebook_session] = facebook_session
|
36
|
+
end
|
37
|
+
facebook_session
|
38
|
+
end
|
39
|
+
|
40
|
+
def log_in_via_fb_id(facebook_user)
|
41
|
+
if user = ::User.find_by_fb_uid(facebook_user.uid)
|
42
|
+
log_in(user)
|
43
|
+
true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def log_in_via_email_hash(facebook_user)
|
48
|
+
facebook_user.email_hashes.each do |hash|
|
49
|
+
if user = ::User.find_by_email_hash(hash)
|
50
|
+
user.update_attribute(:fb_uid, facebook_user.uid)
|
51
|
+
log_in(user)
|
52
|
+
return true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
false
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<fb:login-button onclick="redirect_to_authenticate()"></fb:login-button>
|
2
|
+
<%= javascript_include_tag 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php' %>
|
3
|
+
<script type="text/javascript" charset="utf-8">
|
4
|
+
function redirect_to_authenticate() {
|
5
|
+
FB.Facebook.get_sessionState().waitUntilReady(function() {
|
6
|
+
window.location = window.facebook_authenticate_location;
|
7
|
+
});
|
8
|
+
};
|
9
|
+
|
10
|
+
window.api_key = "<%= SimpleFacebookConnect.api_key %>";
|
11
|
+
window.facebook_authenticate_location = '<%= fb_authenticate_path %>';
|
12
|
+
window.xd_receiver = '/xd_receiver.html';
|
13
|
+
|
14
|
+
FB.init(window.api_key, window.xd_receiver);
|
15
|
+
</script>
|
@@ -0,0 +1,4 @@
|
|
1
|
+
ActionController::Routing::Routes.draw do |map|
|
2
|
+
map.fb_connect '/fb/connect', :controller => 'simple_facebook_connect/connect', :action => 'connect'
|
3
|
+
map.fb_authenticate '/fb/authenticate', :controller => 'simple_facebook_connect/connect', :action => 'authenticate'
|
4
|
+
end
|
data/generators/simple_facebook_connect_features/simple_facebook_connect_features_generator.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
class SimpleFacebookConnectFeaturesGenerator < Rails::Generator::Base
|
2
|
+
def manifest
|
3
|
+
record do |r|
|
4
|
+
r.file 'facebook_connect.feature', "features/facebook_connect.feature"
|
5
|
+
r.file 'facebook_connect_steps.rb', "features/step_definitions/facebook_connect_steps.rb"
|
6
|
+
r.file 'facebook_connect_stubs.rb', "features/support/facebook_connect_stubs.rb"
|
7
|
+
|
8
|
+
r.directory 'features/fixtures/facebook.auth.getSession'
|
9
|
+
r.file 'facebook_auth_getsession.xml', "features/fixtures/facebook.auth.getSession/default.xml"
|
10
|
+
r.directory 'features/fixtures/facebook.users.getInfo'
|
11
|
+
r.file 'facebook_users_getinfo.xml', "features/fixtures/facebook.users.getInfo/default.xml"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<auth_getSession_response
|
3
|
+
xmlns="http://api.facebook.com/1.0/"
|
4
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
5
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
|
6
|
+
<session_key>5f34e11bfb97c762e439e6a5-8055</session_key>
|
7
|
+
<uid>8055</uid>
|
8
|
+
<expires>1173309298</expires>
|
9
|
+
</auth_getSession_response>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: facebook connect
|
2
|
+
In order to get more users
|
3
|
+
As a site owner
|
4
|
+
I want users to easily sign in and sign up via facebook
|
5
|
+
|
6
|
+
Scenario: sign in via facebook when being connected
|
7
|
+
Given a user who is connected via facebook
|
8
|
+
When I go to the start page
|
9
|
+
And I sign in via facebook
|
10
|
+
Then I should see "Welcome"
|
11
|
+
|
12
|
+
Scenario: sign in via facebook when not being connected
|
13
|
+
Given a user with the email "email@person.com"
|
14
|
+
When I go to the start page
|
15
|
+
And I sign in via facebook
|
16
|
+
Then I should see "Welcome"
|
17
|
+
|
18
|
+
Scenario: sign up via facebook
|
19
|
+
When I go to the start page
|
20
|
+
And I sign up via facebook
|
21
|
+
Then I should not see "Password"
|
22
|
+
When I fill in "Email" with "email@person.com"
|
23
|
+
And I press "Sign Up"
|
24
|
+
|
25
|
+
Then I should see "instructions for confirming"
|
26
|
+
And a confirmation message should be sent to "email@person.com"
|
27
|
+
And my facebook id should be set
|
@@ -0,0 +1,19 @@
|
|
1
|
+
When /I sign up via facebook/ do
|
2
|
+
get fb_authenticate_path
|
3
|
+
response.redirected_to.should include('facebook.com')
|
4
|
+
# go to facebook and come back with auth token
|
5
|
+
post fb_connect_path, auth_token: '3e4a22bb2f5ed75114b0fc9995ea85f1'
|
6
|
+
visit response.redirected_to
|
7
|
+
end
|
8
|
+
|
9
|
+
When /I sign in via facebook/ do
|
10
|
+
When 'I sign up via facebook'
|
11
|
+
end
|
12
|
+
|
13
|
+
Then 'my facebook id should be set' do
|
14
|
+
User.last.fb_uid.should == 8055 # taken from xml fixture
|
15
|
+
end
|
16
|
+
|
17
|
+
Given /a user who is connected via facebook/ do
|
18
|
+
User.make fb_uid: 8055 # make from machinist
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module SimpleFacebookConnect
|
2
|
+
module ServiceStub
|
3
|
+
def read_fixture(method)
|
4
|
+
if File.exists?(fixture_path(method, 'default'))
|
5
|
+
File.read fixture_path(method, 'default')
|
6
|
+
else
|
7
|
+
raise "Missing fixture #{fixture_path(method, 'default')}\nFacebook API Reference: http://wiki.developers.facebook.com/index.php/#{method.sub(/^facebook\./, '')}#Example_Return_XML"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def post(params)
|
12
|
+
method = params.delete(:method)
|
13
|
+
params.delete_if {|k,_| [:v, :api_key, :call_id, :sig].include?(k) }
|
14
|
+
Parser.parse(method, read_fixture(method))
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def fixture_path(method, filename)
|
20
|
+
File.join(Rails.root + 'features/fixtures', method, "#{filename}.xml")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module SessionStub
|
25
|
+
def service
|
26
|
+
unless @service
|
27
|
+
service = Service.new(Session::API_SERVER_BASE_URL, Session::API_PATH_REST, @api_key)
|
28
|
+
service.extend(ServiceStub)
|
29
|
+
@service = service
|
30
|
+
else
|
31
|
+
@service
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
SimpleFacebookConnect::Session.class_eval do
|
38
|
+
def self.new(*args)
|
39
|
+
session = super
|
40
|
+
session.extend SimpleFacebookConnect::SessionStub
|
41
|
+
session
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<users_getInfo_response xmlns="http://api.facebook.com/1.0/"
|
3
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
4
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
|
5
|
+
<user>
|
6
|
+
<uid>8055</uid>
|
7
|
+
<about_me>This field perpetuates the glorification of the ego. Also, it has a character limit.</about_me>
|
8
|
+
<activities>Here: facebook, etc. There: Glee Club, a capella, teaching.</activities>
|
9
|
+
<affiliations list="true">
|
10
|
+
<affiliation>
|
11
|
+
<nid>50453093</nid>
|
12
|
+
<name>Facebook Developers</name>
|
13
|
+
<type>work</type>
|
14
|
+
<status/>
|
15
|
+
<year/>
|
16
|
+
</affiliation>
|
17
|
+
</affiliations>
|
18
|
+
<birthday>November 3</birthday>
|
19
|
+
<books>The Brothers K, GEB, Ken Wilber, Zen and the Art, Fitzgerald, The Emporer's New Mind, The Wonderful Story of Henry Sugar</books>
|
20
|
+
<current_location>
|
21
|
+
<city>Palo Alto</city>
|
22
|
+
<state>California</state>
|
23
|
+
<country>United States</country>
|
24
|
+
<zip>94303</zip>
|
25
|
+
</current_location>
|
26
|
+
<education_history list="true">
|
27
|
+
<education_info>
|
28
|
+
<name>Harvard</name>
|
29
|
+
<year>2003</year>
|
30
|
+
<concentrations list="true">
|
31
|
+
<concentration>Applied Mathematics</concentration>
|
32
|
+
<concentration>Computer Science</concentration>
|
33
|
+
</concentrations>
|
34
|
+
</education_info>
|
35
|
+
</education_history>
|
36
|
+
<email_hashes list="true">
|
37
|
+
<email_hash_elt>2781152470_9f9c29692798573d8c76eaaf053a1911</email_hash_elt>
|
38
|
+
</email_hashes>
|
39
|
+
<family list="true">
|
40
|
+
<family_elt list="true">
|
41
|
+
<family_elt_elt>mother</family_elt_elt>
|
42
|
+
<family_elt_elt>1394244902</family_elt_elt>
|
43
|
+
</family_elt>
|
44
|
+
<family_elt list="true">
|
45
|
+
<family_elt_elt>sister</family_elt_elt>
|
46
|
+
<family_elt_elt>48703107</family_elt_elt>
|
47
|
+
</family_elt>
|
48
|
+
<family_elt list="true">
|
49
|
+
<family_elt_elt>brother</family_elt_elt>
|
50
|
+
<family_elt_elt>1078767258</family_elt_elt>
|
51
|
+
</family_elt>
|
52
|
+
<family_elt list="true">
|
53
|
+
<family_elt_elt>brother</family_elt_elt>
|
54
|
+
<family_elt_elt>John Doe</family_elt_elt>
|
55
|
+
<family_elt_elt/>
|
56
|
+
</family_elt>
|
57
|
+
</family>
|
58
|
+
<first_name>Dave</first_name>
|
59
|
+
<hometown_location>
|
60
|
+
<city>York</city>
|
61
|
+
<state>Pennsylvania</state>
|
62
|
+
<country>United States</country>
|
63
|
+
</hometown_location>
|
64
|
+
<hs_info>
|
65
|
+
<hs1_name>Central York High School</hs1_name>
|
66
|
+
<hs2_name/>
|
67
|
+
<grad_year>1999</grad_year>
|
68
|
+
<hs1_id>21846</hs1_id>
|
69
|
+
<hs2_id>0</hs2_id>
|
70
|
+
</hs_info>
|
71
|
+
<is_app_user>1</is_app_user>
|
72
|
+
<has_added_app>1</has_added_app>
|
73
|
+
<interests>coffee, computers, the funny, architecture, code breaking,snowboarding, philosophy, soccer, talking to strangers</interests>
|
74
|
+
<last_name>Fetterman</last_name>
|
75
|
+
<locale>en_US</locale>
|
76
|
+
<meeting_for list="true">
|
77
|
+
<seeking>Friendship</seeking>
|
78
|
+
</meeting_for>
|
79
|
+
<meeting_sex list="true">
|
80
|
+
<sex>female</sex>
|
81
|
+
</meeting_sex>
|
82
|
+
<movies>Tommy Boy, Billy Madison, Fight Club, Dirty Work, Meet the Parents, My Blue Heaven, Office Space </movies>
|
83
|
+
<music>New Found Glory, Daft Punk, Weezer, The Crystal Method, Rage, the KLF, Green Day, Live, Coldplay, Panic at the Disco, Family Force 5</music>
|
84
|
+
<name>Dave Fetterman</name>
|
85
|
+
<notes_count>0</notes_count>
|
86
|
+
<pic>http://photos-055.facebook.com/ip007/profile3/1271/65/s8055_39735.jpg</pic>
|
87
|
+
<pic_big>http://photos-055.facebook.com/ip007/profile3/1271/65/n8055_39735.jpg</pic_big>
|
88
|
+
<pic_small>http://photos-055.facebook.com/ip007/profile3/1271/65/t8055_39735.jpg</pic_small>
|
89
|
+
<pic_square>http://photos-055.facebook.com/ip007/profile3/1271/65/q8055_39735.jpg</pic_square>
|
90
|
+
<political>Moderate</political>
|
91
|
+
<profile_update_time>1170414620</profile_update_time>
|
92
|
+
<quotes/>
|
93
|
+
<relationship_status>In a Relationship</relationship_status>
|
94
|
+
<religion/>
|
95
|
+
<sex>male</sex>
|
96
|
+
<significant_other_id xsi:nil="true"/>
|
97
|
+
<status>
|
98
|
+
<message>Fast Company, November issue, page 84</message>
|
99
|
+
<time>1193075616</time>
|
100
|
+
</status>
|
101
|
+
<timezone>-8</timezone>
|
102
|
+
<tv>cf. Bob Trahan</tv>
|
103
|
+
<wall_count>121</wall_count>
|
104
|
+
<work_history list="true">
|
105
|
+
<work_info>
|
106
|
+
<location>
|
107
|
+
<city>Palo Alto</city>
|
108
|
+
<state>CA</state>
|
109
|
+
<country>United States</country>
|
110
|
+
</location>
|
111
|
+
<company_name>Facebook</company_name>
|
112
|
+
<position>Software Engineer</position>
|
113
|
+
<description>Tech Lead, Facebook Platform</description>
|
114
|
+
<start_date>2006-01</start_date>
|
115
|
+
<end_date/>
|
116
|
+
</work_info>
|
117
|
+
</work_history>
|
118
|
+
</user>
|
119
|
+
</users_getInfo_response>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class AddFacebookConnect < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :users, :fb_uid, :integer
|
4
|
+
add_column :users, :email_hash, :string
|
5
|
+
|
6
|
+
add_index :users, :fb_uid
|
7
|
+
add_index :users, :email_hash
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
remove_index :users, :fb_uid
|
12
|
+
remove_index :users, :email_hash
|
13
|
+
|
14
|
+
remove_column :users, :email_hash
|
15
|
+
remove_column :users, :fb_uid
|
16
|
+
end
|
17
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/lib/simple_facebook_connect'
|
2
|
+
|
3
|
+
config_file = Rails.root + 'config/simple_facebook_connect.yml'
|
4
|
+
|
5
|
+
unless File.exist?(config_file)
|
6
|
+
File.open(config_file, 'w') do |f|
|
7
|
+
f << <<-CONF
|
8
|
+
test:
|
9
|
+
api_key:
|
10
|
+
secret_key:
|
11
|
+
|
12
|
+
development:
|
13
|
+
api_key:
|
14
|
+
secret_key:
|
15
|
+
|
16
|
+
production:
|
17
|
+
api_key:
|
18
|
+
secret_key:
|
19
|
+
|
20
|
+
CONF
|
21
|
+
end
|
22
|
+
|
23
|
+
puts "Created the facebook simple connect configuration in #{config_file}. Please enter your facebook API and secret keys there."
|
24
|
+
exit(1)
|
25
|
+
end
|
26
|
+
|
27
|
+
config = YAML::load(File.read(config_file))[Rails.env]
|
28
|
+
|
29
|
+
SimpleFacebookConnect.api_key = config['api_key']
|
30
|
+
SimpleFacebookConnect.secret_key = config['secret_key']
|
31
|
+
|
32
|
+
ApplicationController.send(:include, SimpleFacebookConnect::ControllerExtension)
|
33
|
+
User.send(:include, SimpleFacebookConnect::UserExtension)
|
34
|
+
|
35
|
+
require 'simple_facebook_connect/extensions/routes'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module SimpleFacebookConnect
|
2
|
+
module ControllerExtension
|
3
|
+
def facebook_session
|
4
|
+
session[:facebook_session]
|
5
|
+
end
|
6
|
+
|
7
|
+
def facebook_user
|
8
|
+
(session[:facebook_session] && session[:facebook_session].session_key) ? session[:facebook_session].user : nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# without this hack people can't override our routes when subclassing controllers in the app. trick stolen from clearance.
|
2
|
+
class ActionController::Routing::RouteSet
|
3
|
+
def load_routes_with_simple_facebook_connect!
|
4
|
+
lib_path = File.dirname(__FILE__)
|
5
|
+
routes = File.join(lib_path, *%w[.. .. .. config simple_facebook_connect_routes.rb])
|
6
|
+
unless configuration_files.include?(routes)
|
7
|
+
add_configuration_file(routes)
|
8
|
+
end
|
9
|
+
load_routes_without_simple_facebook_connect!
|
10
|
+
end
|
11
|
+
|
12
|
+
alias_method_chain :load_routes!, :simple_facebook_connect
|
13
|
+
end
|