Skip to content

Instantly share code, notes, and snippets.

@kuntoaji
Created March 1, 2010 05:37
Show Gist options
  • Save kuntoaji/318107 to your computer and use it in GitHub Desktop.
Save kuntoaji/318107 to your computer and use it in GitHub Desktop.
class UserSessionsController < ApplicationController
before_filter :require_logout, :only => [:new, :create, :auth_fb_connect]
before_filter :set_facebook_session, :only => [:new, :create, :destroy, :auth_fb_connect]
helper_method :facebook_session, :only => [:new, :create, :destroy, :auth_fb_connect]
def new
@user_session = UserSession.new
end
def create
@user_session ||= UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = "Welcome #{current_user.name}!"
redirect_to account_path(current_user)
else
render "new"
end
end
def destroy
current_user_session && current_user_session.destroy
# Facebook
if facebook_session
clear_fb_cookies!
clear_facebook_session_information
end
flash[:notice] = "Successfully logout!"
redirect_to login_path
end
def auth_fb_connect
if facebook_session && facebook_session.user && !facebook_session.expired?
@user = User.find_by_facebook_uid(facebook_session.user.id)
if @user
@user_session = UserSession.new(@user)
create
else
# do something to validate user with facebook
end
else
clear_fb_cookies!
clear_facebook_session_information
redirect_to root_path
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment