Created
March 1, 2010 05:37
-
-
Save kuntoaji/318107 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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