Skip to content

Commit

Permalink
Use UserReturnToStorer in ControllerHelpers::Auth module
Browse files Browse the repository at this point in the history
By using Spree::UserReturnToStorer one can change
ControllerHelpers::Auth#store_location behavior without
resorting to monkey patching.
  • Loading branch information
spaghetticode committed Oct 18, 2019
1 parent 12b7cd3 commit f125400
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,11 @@ Spree.user_class = <%= (options[:user_class].blank? ? "Spree::LegacyUser" : opti
# just uncomment the following code and change it as you need.
#
# Spree::Model.whitelisted_ransackable_attributes << 'field'

# Rules for avoiding to store the current path into session for redirects
# When at least one rule is matched, the request path will not be stored
# in session.
# You can add your custom rules by uncommenting this line and changing
# the class name:
#
# Spree::UserReturnToStorer.rules << 'Spree::UrlReturnToStorer::Rules::AuthenticationRule'
14 changes: 1 addition & 13 deletions core/lib/spree/core/controller_helpers/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,7 @@ def set_guest_token
end

def store_location
# disallow return to login, logout, signup pages
authentication_routes = [:spree_signup_path, :spree_login_path, :spree_logout_path]
disallowed_urls = []
authentication_routes.each do |route|
if respond_to?(route)
disallowed_urls << send(route)
end
end

disallowed_urls.map!{ |url| url[/\/\w+$/] }
unless disallowed_urls.include?(request.fullpath)
session['spree_user_return_to'] = request.fullpath.gsub('//', '/')
end
Spree::UserReturnToStorer.new(self).store_location
end

# proxy method to *possible* spree_current_user method
Expand Down

0 comments on commit f125400

Please sign in to comment.