Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Returns a user associated with a facebook account.
- def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
- data = access_token.extra.raw_info
- if user = User.where(:email => data.email).first
- user
- else # Create a user with a stub password.
- user = User.new email: data.email, first_name: data.first_name, last_name: data.last_name, password: Devise.friendly_token[0,20]
- facebook_id = data.id
- token = access_token.credentials.token
- user.facebook_info = { 'id' => facebook_id, 'token' => token }
- # in the future we could save the user and get the friends in a background worker if it's too slow
- fb_user = FbGraph::User.fetch facebook_id, access_token: token
- user.facebook_friends = fb_user.friends.map &:identifier
- user.save!
- user.confirm!
- user
- end
- end
Add Comment
Please, Sign In to add comment