Skip to content

Instantly share code, notes, and snippets.

@pnegri
Created June 22, 2012 20:01
Show Gist options
  • Save pnegri/2974819 to your computer and use it in GitHub Desktop.
Save pnegri/2974819 to your computer and use it in GitHub Desktop.
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