Skip to content

Instantly share code, notes, and snippets.

@tohyongcheng
Last active August 29, 2015 13:56
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 tohyongcheng/8910948 to your computer and use it in GitHub Desktop.
Save tohyongcheng/8910948 to your computer and use it in GitHub Desktop.
merge existing account when fb login
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
if user
return user
else
registered_user = User.where(:email => auth.info.email).first
if registered_user
registered_user.update_attributes(:provider => auth.provider, :uid => auth.uid, picture: (URI.parse(auth.info.image.split("?")[0] << "?width=200&height=200") if auth.info.image?) )
return registered_user
else
user = User.create( name:auth.extra.raw_info.name,
provider:auth.provider,
uid:auth.uid,
email:auth.info.email,
password:Devise.friendly_token[0,20],
picture: (URI.parse(auth.info.image.split("?")[0] << "?width=200&height=200") if auth.info.image?)
)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment