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.

33 lines
932 B

  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. sign_in_and_redirect @user, event: :authentication
  10. set_flash_message(:notice, :success, kind: provider_id.capitalize) if is_navigational_format?
  11. else
  12. session["devise.#{provider}_data"] = request.env['omniauth.auth']
  13. redirect_to new_user_registration_url
  14. end
  15. end
  16. end
  17. Devise.omniauth_configs.each_key do |provider|
  18. provides_callback_for provider
  19. end
  20. def after_sign_in_path_for(resource)
  21. if resource.email_verified?
  22. root_path
  23. else
  24. finish_signup_path
  25. end
  26. end
  27. end