Skip to content

Commit

Permalink
[SD-613] Fixes redirect to paths after sign up (#478)
Browse files Browse the repository at this point in the history
* Fixes redirect to paths after sign in in user_registrations_controller.rb

* Changes after_inactive_sign_up_path_for in user_registrations_controller.rb

* Changes account_path to spree_account path in user_registrations_controller.rb
  • Loading branch information
PSzyszkaSpark authored Feb 20, 2020
1 parent 2f592a7 commit 4ec80f7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/controllers/spree/user_registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create
set_flash_message :notice, :signed_up
sign_up(resource_name, resource)
session[:spree_user_signup] = true
respond_with resource, location: after_sign_up_path_for(resource)
redirect_to_checkout_or_account_path(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}"
expire_data_after_sign_in!
Expand Down Expand Up @@ -80,6 +80,13 @@ def after_sign_up_path_for(resource)
after_sign_in_redirect(resource) if is_navigational_format?
end

def after_inactive_sign_up_path_for(resource)
scope = Devise::Mapping.find_scope!(resource)
router_name = Devise.mappings[scope].router_name
context = router_name ? send(router_name) : self
context.respond_to?(:login_path) ? context.login_path : "/login"
end

private

def spree_user_params
Expand All @@ -89,4 +96,14 @@ def spree_user_params
def after_sign_in_redirect(resource_or_scope)
stored_location_for(resource_or_scope) || account_path
end

def redirect_to_checkout_or_account_path(resource)
resource_path = after_sign_up_path_for(resource)

if resource_path == spree.checkout_state_path(:address)
respond_with resource, location: spree.checkout_state_path(:address)
else
respond_with resource, location: spree.account_path
end
end
end

0 comments on commit 4ec80f7

Please sign in to comment.