public
anonymous / gist:4356065
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
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

My version also has this:

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.