Module: MnoEnterprise::Concerns::Controllers::Auth::OmniauthCallbacksController::ClassMethods

Defined in:
lib/mno_enterprise/concerns/controllers/auth/omniauth_callbacks_controller.rb

Overview

Class methods

Instance Method Summary collapse

Instance Method Details

#provides_callback_for(provider) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mno_enterprise/concerns/controllers/auth/omniauth_callbacks_controller.rb', line 52

def provides_callback_for(provider)
  class_eval %Q{
    def #{provider}
      auth = env["omniauth.auth"]
      opts = { orga_on_create: create_orga_on_user_creation(auth.info.email) }

      @user = MnoEnterprise::User.find_for_oauth(auth, opts, current_user)

      if @user.persisted?
        sign_in_and_redirect @user, event: :authentication
        set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format?
      else
        session["devise.#{provider}_data"] = env["omniauth.auth"]
        redirect_to new_user_registration_url
      end
    end
  }
end