Created
June 22, 2012 20:01
-
-
Save pnegri/2974819 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
def self.find_or_create_by_social(auth) | |
social_account = SocialAccount.where("provider = ? AND social_id = ?", auth["provider"], auth["uid"]).first | |
update_token = true | |
unless user = social_account.try(:user) | |
user = User.new | |
if auth["extra"]["raw_info"]["email"] | |
return false if !User.where(:email => auth["extra"]["raw_info"]["email"]).empty? | |
user.email = auth["extra"]["raw_info"]["email"] | |
end | |
# user.skip_confirmation! | |
user.save(:validate => false) | |
social_account = user.create_social(auth) | |
update_token = false | |
end | |
social_account.update_attribute( 'token', auth['credentials']['token'] ) if update_token | |
user | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment