Created
December 21, 2012 21:50
-
-
Save anonymous/4356065 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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My version also has this: