Permalink
Browse files

tweak User model to handle LinkedIn

  • Loading branch information...
1 parent e3480c7 commit 64fb2ff470522bc70c3c80c37c062a6c505772fb @fortuity fortuity committed May 8, 2011
Showing with 15 additions and 7 deletions.
  1. +15 −7 app/models/user.rb
View
@@ -7,13 +7,21 @@ class User
attr_accessible :provider, :uid, :name, :email
def self.create_with_omniauth(auth)
- create! do |user|
- user.provider = auth['provider']
- user.uid = auth['uid']
- user.name = auth['user_info']['name'] if auth['user_info']['name'] # Twitter, Google, Yahoo, GitHub
- user.email = auth['user_info']['email'] if auth['user_info']['email'] # Google, Yahoo, GitHub
- user.name = auth['extra']['user_hash']['name'] if auth['extra']['user_hash']['name'] # Facebook
- user.email = auth['extra']['user_hash']['email'] if auth['extra']['user_hash']['email'] # Facebook
+ begin
+ create! do |user|
+ user.provider = auth['provider']
+ user.uid = auth['uid']
+ if auth['user_info']
+ user.name = auth['user_info']['name'] if auth['user_info']['name'] # Twitter, Google, Yahoo, GitHub
+ user.email = auth['user_info']['email'] if auth['user_info']['email'] # Google, Yahoo, GitHub
+ end
+ if auth['extra']['user_hash']
+ user.name = auth['extra']['user_hash']['name'] if auth['extra']['user_hash']['name'] # Facebook
+ user.email = auth['extra']['user_hash']['email'] if auth['extra']['user_hash']['email'] # Facebook
+ end
+ end
+ rescue Exception
+ raise Exception, "cannot create user record"
end
end

0 comments on commit 64fb2ff

Please sign in to comment.