Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
<html>
<head>
<%= javascript_include_tag :defaults %>
<%= fb_connect_javascript_tag %>
</head>
<body>
<%= fb_connect_javascript_tag %>
<%= init_fb_connect "XFBML" %>
</body>
</html>
def ensure_authenticated_to_facebook
set_facebook_session || create_new_facebook_session_and_redirect!
end
def set_facebook_session
# first, see if we already have a session
session_set = session_already_secured?
# if not, see if we can load it from the environment
unless session_set
session_set = create_facebook_session
session[:facebook_session] = @facebook_session if session_set
end
if session_set
capture_facebook_friends_if_available!
Session.current = facebook_session
end
return session_set
end
def create_facebook_session
secure_with_facebook_params! || secure_with_cookies! || secure_with_token!
end
<%= authlogic_facebook_login_button :length => "long" %>
class UserSessionsController < ApplicationController
before_filter :check_fb, :only => :create
#...
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save && !@user_session.user.suspended?
unless @user_session.user.facebook_uid.nil?
@user_session.user.active = true
@user_session.user.save
end
flash[:notice] = t(:msg_welcome)
if @user_session.user.login_count > 1 && @user_session.user.last_login_at?
flash[:notice] << " " << t(:msg_last_login, @user_session.user.last_login_at.to_s(:mmddhhss))
end
redirect_back_or_default root_url
else
#...
end
end
#...
private
def check_fb
if params[:user_session].nil?
ensure_authenticated_to_facebook
end
end
end
describe UserSessionsController do
describe "create" do
describe "facebook user" do
it "creates account based on facebook details" do
FakeWeb.allow_net_connect = false
FakeWeb.register_uri(:post, "http://api.facebook.com/restserver.php", :body => Rails.root + "spec/fixtures/get_users_info.xml")
setup_fb_connect_cookies
post :create
response.should redirect_to(root_url)
@assigned_user = assigns[:user_session].user
@assigned_user.new_record?.should be_false
@assigned_user.active.should be_true
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.