Advertisement
Guest User

Untitled

a guest
May 16th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  2.  
  3. def facebook
  4. @user = User.from_omniauth(request.env["omniauth.auth"])
  5.  
  6. if @user.persisted?
  7. sign_in_and_redirect @user, :event => :authentication
  8. set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
  9. else
  10. session["devise.facebook_data"] = request.env["omniauth.auth"]
  11. redirect_to new_user_registration_url
  12. end
  13. end
  14.  
  15. def google_oauth2
  16. @user = User.from_omniauth(request.env['omniauth.auth'])
  17.  
  18. if @user.persisted?
  19. sign_in_and_redirect @user, :event => :authentication
  20. set_flash_message(:notice, :success, :kind => "Google") if is_navigational_format?
  21. else
  22. session["devise.google_oauth2_data"] = request.env["omniauth.auth"]
  23. redirect_to new_user_registration_url
  24. end
  25. end
  26.  
  27. def self.from_omniauth(auth)
  28. where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
  29. user.fullname = auth.info.name
  30. user.provider = auth.provider
  31. user.uid = auth.uid
  32. user.email = auth.info.email
  33. user.image = auth.info.image
  34. user.password = Devise.friendly_token[0,20]
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement