Guest User

Untitled

a guest
Jun 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. class AuthenticationsController < ApplicationController
  2. def index
  3. @authentications = current_user.authentications if current_user
  4. end
  5.  
  6. def create
  7. omniauth = request.env["omniauth.auth"]
  8. authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
  9.  
  10. if authentication
  11. flash[:notice] = "Signed in successfully."
  12. # use devise helper method to sign in user and redirect
  13. sign_in_and_redirect(:user, authentication.user)
  14. elsif current_user
  15. current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
  16. flash[:notice] = "Authentication successful."
  17. redirect_to authentications_url
  18. else
  19. user = User.new
  20. user.apply_omniauth(omniauth)
  21.  
  22. if user.save
  23. flash[:notice] = "Signed in successfully."
  24. sign_in_and_redirect(:user, user)
  25. else
  26. session[:omniauth] = omniauth.except('extra') # exclude the extra stuff - won't fit in cookie
  27. redirect_to new_user_registration_url
  28. end
  29. end
  30. end
  31.  
  32. def destroy
  33. @authentication = current_user.authentications.find(params[:id])
  34. @authentication.destroy
  35. flash[:notice] = "Successfully destroyed authentication."
  36. redirect_to authentications_url
  37. end
  38.  
  39. def failure
  40. end
  41. end
Add Comment
Please, Sign In to add comment