Class: Spree::OmniauthCallbacksController
- Inherits:
-
Devise::OmniauthCallbacksController
- Object
- Devise::OmniauthCallbacksController
- Spree::OmniauthCallbacksController
- Includes:
- RouteResolver, Core::ControllerHelpers::Auth, Core::ControllerHelpers::Common, Core::ControllerHelpers::Order, Core::ControllerHelpers::Store
- Defined in:
- app/controllers/spree/omniauth_callbacks_controller.rb
Class Method Summary collapse
Instance Method Summary collapse
- #after_sign_in_path_for(resource_or_scope) ⇒ Object
- #auth_hash ⇒ Object
- #failure ⇒ Object
- #omniauth_callback ⇒ Object
- #passthru ⇒ Object
Methods included from RouteResolver
Class Method Details
.provides_callback_for(*providers) ⇒ Object
11 12 13 14 15 |
# File 'app/controllers/spree/omniauth_callbacks_controller.rb', line 11 def provides_callback_for(*providers) providers.each do |provider| define_method(provider) { omniauth_callback } end end |
Instance Method Details
#after_sign_in_path_for(resource_or_scope) ⇒ Object
73 74 75 |
# File 'app/controllers/spree/omniauth_callbacks_controller.rb', line 73 def after_sign_in_path_for(resource_or_scope) stored_location_for(resource_or_scope) || resolve_route_for(:account_path) end |
#auth_hash ⇒ Object
69 70 71 |
# File 'app/controllers/spree/omniauth_callbacks_controller.rb', line 69 def auth_hash request.env['omniauth.auth'] end |
#failure ⇒ Object
60 61 62 63 |
# File 'app/controllers/spree/omniauth_callbacks_controller.rb', line 60 def failure :alert, :failure, kind: failed_strategy.name.to_s.humanize, reason: redirect_to resolve_route_for(:login_path) end |
#omniauth_callback ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/spree/omniauth_callbacks_controller.rb', line 22 def omniauth_callback if request.env['omniauth.error'].present? flash[:error] = I18n.t('devise.omniauth_callbacks.failure', kind: auth_hash['provider'], reason: I18n.t('spree.user_was_not_valid')) redirect_back_or_default(resolve_route_for(:root_url)) return end authentication = Spree::UserAuthentication.find_by(provider: auth_hash['provider'], uid: auth_hash['uid']) if authentication.present? && authentication.try(:user).present? flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: auth_hash['provider']) sign_in_and_redirect :spree_user, authentication.user elsif spree_current_user spree_current_user.apply_omniauth(auth_hash) spree_current_user.save! flash[:notice] = I18n.t('devise.sessions.signed_in') redirect_back_or_default(resolve_route_for(:account_url)) else user = Spree.user_class.find_by(email: auth_hash['info']['email']) || Spree.user_class.new user.apply_omniauth(auth_hash) if user.save flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: auth_hash['provider']) sign_in_and_redirect :spree_user, user else session[:omniauth] = auth_hash.except('extra') flash[:notice] = I18n.t('spree.one_more_step', kind: auth_hash['provider'].capitalize) redirect_to resolve_route_for(:new_spree_user_registration_url) return end end if current_order user = spree_current_user || authentication.user current_order.associate_user!(user) session[:guest_token] = nil end end |
#passthru ⇒ Object
65 66 67 |
# File 'app/controllers/spree/omniauth_callbacks_controller.rb', line 65 def passthru render file: "#{Rails.root}/public/404.html", formats: [:html], status: :not_found, layout: false end |