Skip to content

Instantly share code, notes, and snippets.

Created December 21, 2012 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4356065 to your computer and use it in GitHub Desktop.
Save anonymous/4356065 to your computer and use it in GitHub Desktop.
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
facebook_omniauth = request.env["omniauth.auth"]
# user exists with fb connect; sign them in
if @user = User.find_for_facebook_oauth(facebook_omniauth, current_user)
# connect FB with existing account
elsif @user = User.where(email: facebook_omniauth.info.email).first
@user.provider = auth.provider
@user.uid = auth.uid
@user.save
# FB account AND account with same email do not exist: create a new account with FB?
elsif 1 # person clicks "yes, make a new account with this email"
@user = User.create(name: facebook_omniauth.extra.raw_info.name,
provider: facebook_omniauth.provider,
uid: facebook_omniauth.uid,
email: facebook_omniauth.info.email,
invite_code: (0...8).map{65.+(rand(25)).chr}.join,
password: Devise.friendly_token[0,20])
@user.build_fit_profile
@user.build_current_shipment
else
flash[:alert] = "Please create an account."
redirect_to new_registration_path
end
if @user
sign_in(@user, bypass: true)
redirect_to recommendations_path
end
end
end
@DFrenkel
Copy link

My version also has this:

  def passthrough
    raise ActionController::RoutingError.new('Not Found')
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment