Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. class User < ActiveRecord
  2.  
  3. #....
  4.  
  5. def self.from_omniauth(auth)
  6. where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
  7.  
  8. #p auth
  9.  
  10. user.email = auth.info.email
  11. user.password = Devise.friendly_token[0,20]
  12. user.name = auth.info.first_name
  13. user.surname = auth.info.last_name
  14.  
  15. #p "RANGO DE EDAD FB = #{auth.extra.raw_info.age_range.min}, #{auth.extra.raw_info.age_range.max}"
  16.  
  17. user.adult = auth.extra.raw_info.age_range.min[FB_MIN_AGE_INDEX] >= ADULT_AGE
  18.  
  19.  
  20.  
  21. #user.image = auth.info.image # assuming the user model has an image
  22.  
  23.  
  24. # Nos saltamos el email de confirmación
  25. user.skip_confirmation!
  26. end
  27. end
  28.  
  29. class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  30.  
  31. def facebook
  32.  
  33. @user = User.from_omniauth(request.env["omniauth.auth"])
  34.  
  35. if(@user.persisted?)
  36.  
  37. sign_in_and_redirect @user, :event => :authentication
  38. set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
  39.  
  40. else
  41.  
  42. session["devise.facebook_data"] = request.env["omniauth.auth"]
  43.  
  44. redirect_to new_user_registration_url
  45.  
  46. end
  47.  
  48. end
  49.  
  50. def failure
  51.  
  52. redirect_to root_path
  53.  
  54. end
  55.  
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement