Guest User

Untitled

a guest
Jul 6th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. omniauth_controller.rb
  2.  
  3. def sign_in_oauth_from_provider
  4. result = AuthenticateUser.call(omniauth: request.env['omniauth.auth'])
  5. #@user = User.find_for_oauth(request.env['omniauth.auth'])
  6. #if @user.persisted?
  7. if result.success?
  8. sign_in_and_redirect @user, event: :authentication
  9. set_flash_message(:notice, :success, kind: @provider_auth) if is_navigational_format?
  10. end
  11. end
  12.  
  13.  
  14. INTERACTOR
  15.  
  16. class AuthenticateUser
  17. include Interactor
  18.  
  19. def call
  20. context.omniauth
  21. if context.save
  22. context.sucess(message: 'omniauth true')
  23. authorization = OauthProvider.where(provider: auth.provider, uid: auth.uid.to_s).first
  24. return authorization.user if authorization
  25.  
  26. email = auth.info[:email]
  27. user = User.where(email: email).first
  28. if user
  29. user.oauth_providers.create(provider: auth.provider, uid: auth.uid)
  30. else
  31. password = Devise.friendly_token[0, 20]
  32. user = User.create!(email: email, password: password, password_confirmation: password)
  33. user.oauth_providers.create(provider: auth.provider, uid: auth.uid)
  34. end
  35. user
  36. # context.sucess(message: 'omniauth true')
  37. else
  38. context.fail!
  39. end
  40. end
  41. end
  42.  
  43. Error
  44. OmniauthCallbacksController#github is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: [] NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.
Add Comment
Please, Sign In to add comment