Created
October 25, 2012 15:38
-
-
Save mikepence/3953440 to your computer and use it in GitHub Desktop.
Code to fetch Facebook image for Catarse
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.create_with_omniauth(auth, primary_user_id = nil) | |
u = create! do |user| | |
user.provider = auth["provider"] | |
user.uid = auth["uid"] | |
user.name = auth["user_info"]["name"] | |
user.name = auth["user_info"][:name] if user.name.nil? | |
user.email = auth["user_info"]["email"] | |
user.email = auth["extra"]["user_hash"]["email"] if auth["extra"] and auth["extra"]["user_hash"] and user.email.nil? | |
user.nickname = auth["user_info"]["nickname"] | |
user.bio = auth["user_info"]["description"][0..139] if auth["user_info"]["description"] | |
if auth["provider"] == "facebook" | |
user.image_url = "http://graph.facebook.com/#{auth["uid"]}/picture" | |
else | |
user.image_url = auth["user_info"]["image"] | |
end | |
user.locale = I18n.locale.to_s | |
end | |
# If we could not associate by email we try to use the parameter | |
if u.primary.nil? and primary_user_id | |
u.primary = User.find_by_id(primary_user_id) | |
end | |
u.primary.nil? ? u : u.primary | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment