correct facebook logic

This commit is contained in:
Sam 2013-08-26 18:01:01 +10:00
parent ac905d4a08
commit 982b763216
2 changed files with 2 additions and 5 deletions

View File

@ -14,10 +14,6 @@ class Auth::Authenticator
# not required
end
def lookup_user(user_info, email)
user_info.try(:user) || User.where(email: email).first
end
# hook used for registering omniauth middleware,
# without this we can not authenticate
def register_middleware(omniauth)

View File

@ -17,8 +17,9 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
result.extra_data = facebook_hash
user_info = FacebookUserInfo.where(facebook_user_id: facebook_hash[:facebook_user_id]).first
result.user = user_info.try(:user)
if !user_info && result.user = lookup_user(user_info, email)
if !result.user && result.user = User.where(email: Email.downcase(email)).first
FacebookUserInfo.create({user_id: result.user.id}.merge(facebook_hash))
end