You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. class Auth::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  3. skip_before_action :verify_authenticity_token
  4. def self.provides_callback_for(provider)
  5. provider_id = provider.to_s.chomp '_oauth2'
  6. define_method provider do
  7. @user = User.find_for_oauth(request.env['omniauth.auth'], current_user)
  8. if @user.persisted?
  9. LoginActivity.create(
  10. user: @user,
  11. success: true,
  12. authentication_method: :omniauth,
  13. provider: provider,
  14. ip: request.remote_ip,
  15. user_agent: request.user_agent
  16. )
  17. sign_in_and_redirect @user, event: :authentication
  18. set_flash_message(:notice, :success, kind: provider_id.capitalize) if is_navigational_format?
  19. else
  20. session["devise.#{provider}_data"] = request.env['omniauth.auth']
  21. redirect_to new_user_registration_url
  22. end
  23. end
  24. end
  25. Devise.omniauth_configs.each_key do |provider|
  26. provides_callback_for provider
  27. end
  28. def after_sign_in_path_for(resource)
  29. if resource.email_verified?
  30. root_path
  31. else
  32. auth_setup_path(missing_email: '1')
  33. end
  34. end
  35. end