Permalink
Browse files

When the user logs in with facebook I've added a check to see if this…

… user currently has an account in their fb email address. TODO: Add checks for other services like Twitter and possibly find a better location for it
  • Loading branch information...
1 parent f32a63c commit f312597ca09ce6933f02935283b22c10d8ec5208 Jonathan Spooner committed Oct 25, 2010
Showing with 28 additions and 0 deletions.
  1. +28 −0 lib/authlogic_connect/oauth/session.rb
View
28 lib/authlogic_connect/oauth/session.rb
@@ -39,12 +39,40 @@ def complete_oauth_transaction
# this is searching with User.find ...
# attempted_record is part of AuthLogic
hash = oauth_token_and_secret
+ puts "////////////////////////// OAUTH"
+ puts "////////////////////////// OAUTH #{hash}"
+ puts "////////////////////////// OAUTH.inspect #{hash.inspect}"
+ puts "////////////////////////// hash[:key] #{hash[:key]}"
+ puts "////////////////////////// hash[:token] #{hash[:token]}"
token = token_class.find_by_key_or_token(hash[:key], hash[:token], :include => [:user]) # some weird error if I leave out the include)
if token
self.attempted_record = token.user
elsif auto_register?
self.attempted_record = klass.new
self.attempted_record.access_tokens << token_class.new(hash)
+
+ puts "////////////// FACEBOOK TOKEN??? #{self.attempted_record.get_token(:facebook)}"
+ puts "////////////// FACEBOOK TOKEN??? #{self.attempted_record.get_token(:facebook).inspect}"
+ # If it's a facebook token lets look up the users email address
+ if self.attempted_record.has_token?(:facebook)
+ self.attempted_record.active_token = self.attempted_record.get_token(:facebook)
+ facebook = JSON.parse(self.attempted_record.active_token.get("/me"))
+ puts "////////////// FACEBOOK DETAILS #{facebook.inspect}"
+ puts "////////////// FACEBOOK EMAIL #{facebook[:email]}"
+
+ if facebook["email"]
+ existing_user = klass.find_by_email(facebook["email"])
+ puts "////////////// FACEBOOK DETAILS YES YES YES YES #{existing_user} #{existing_user.inspect}"
+ if existing_user
+ self.attempted_record = existing_user
+ self.attempted_record.access_tokens << token_class.new(hash)
+ puts "///////// FACEBOOK HOLY SHIT IT's WORKING BEeeeeACH"
+ end
+ end
+
+ end
+
+
self.attempted_record.save
else
auth_session[:_key] = hash[:key]

0 comments on commit f312597

Please sign in to comment.