Guest User

Untitled

a guest
Sep 21st, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. # Returns a user associated with a facebook account.
  2. def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
  3. data = access_token.extra.raw_info
  4. if user = User.where(:email => data.email).first
  5. user
  6. else # Create a user with a stub password.
  7. user = User.new email: data.email, first_name: data.first_name, last_name: data.last_name, password: Devise.friendly_token[0,20]
  8.  
  9. facebook_id = data.id
  10. token = access_token.credentials.token
  11.  
  12. user.facebook_info = { 'id' => facebook_id, 'token' => token }
  13.  
  14. # in the future we could save the user and get the friends in a background worker if it's too slow
  15. fb_user = FbGraph::User.fetch facebook_id, access_token: token
  16. user.facebook_friends = fb_user.friends.map &:identifier
  17.  
  18. user.save!
  19. user.confirm!
  20. user
  21. end
  22. end
Add Comment
Please, Sign In to add comment