Guest User

Untitled

a guest
Jun 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. class AuthenticationsController < ApplicationController
  2.  
  3. def create
  4. omniauth = request.env['omniauth.auth']
  5.  
  6. authentication = Authentication.find_by_provider_and_uid(
  7. omniauth['provider'], omniauth['uid'])
  8.  
  9. if authentication
  10. flash[:notice] = 'Signed in successfully.'
  11.  
  12. sign_in_and_redirect(:user, authentication.user)
  13. elsif current_user
  14. current_user.authentications.create!(
  15. :provider => omniauth['provider'], :uid => omniauth['uid'])
  16. flash[:notice] = "Authentication successful."
  17.  
  18. redirect_to authentications_url
  19. else
  20. user = User.new
  21. user.apply_omniauth(omniauth)
  22. user.save!
  23.  
  24. flash[:notice] = 'Signed in successfully.'
  25. sign_in_and_redirect(:user, user)
  26. end
  27. end
  28.  
  29. end
Add Comment
Please, Sign In to add comment