Skip to content

Commit 5dfb2e7

Browse files
cpfergus1elia
authored andcommitted
Only use custom routes
Using both devise generated routes and custom ones is confusing. As an example: when failing authentication, the devise route would send the user to "new_spree_user_session_path", however we want our users to be redirected to "/login." This commit deprecates the route and sends users to "/login."
1 parent 5e71eec commit 5dfb2e7

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

config/routes.rb

+39-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
passwords: 'spree/user_passwords',
1111
confirmations: 'spree/user_confirmations'
1212
},
13-
skip: [:unlocks, :omniauth_callbacks],
13+
skip: :all,
1414
path_names: { sign_out: 'logout' },
1515
path_prefix: :user,
1616
router_name: :spree
@@ -19,16 +19,44 @@
1919
resources :users, only: [:edit, :update]
2020

2121
devise_scope :spree_user do
22-
get '/login', to: 'user_sessions#new', as: :login
23-
post '/login', to: 'user_sessions#create', as: :create_new_session
24-
match '/logout', to: 'user_sessions#destroy', as: :logout, via: Devise.sign_out_via
25-
get '/signup', to: 'user_registrations#new', as: :signup
26-
post '/signup', to: 'user_registrations#create', as: :registration
27-
get '/password/recover', to: 'user_passwords#new', as: :recover_password
28-
post '/password/recover', to: 'user_passwords#create', as: :reset_password
29-
get '/password/change', to: 'user_passwords#edit', as: :edit_password
30-
put '/password/change', to: 'user_passwords#update', as: :update_password
31-
get '/confirm', to: 'user_confirmations#show', as: :confirmation if Spree::Auth::Config[:confirmable]
22+
# Legacy devise generated paths
23+
#
24+
# These are deprecated but we still want to support the incoming routes, in order to give existing stores an upgrade path.
25+
# Will be removed at the next major release of solidus_auth_devise.
26+
get '/user/spree_user/password/edit' => 'user_passwords#edit', as: :deprecated_edit_spree_user_password, deprecated_route: true
27+
get '/password/change' => 'user_passwords#edit', as: :edit_spree_user_password, deprecated_route: true
28+
get '/user/spree_user/password/new' => 'user_passwords#new', as: :deprecated_new_spree_user_password, deprecated_route: true
29+
get '/password/recover' => 'user_passwords#new', as: :new_spree_user_password, deprecated_route: true
30+
match '/user/spree_user/password' => 'user_passwords#update', via: [:patch, :put], as: :deprecated_spree_user_password, deprecated_route: true
31+
put '/password/change' => 'user_passwords#update', as: :spree_user_password, deprecated_route: true
32+
post '/user/spree_user/password' => 'user_passwords#create', as: nil, deprecated_route: true
33+
34+
get '/login' => 'user_sessions#new', as: :new_spree_user_session, deprecated_route: true
35+
get '/user/spree_user/sign_in' => 'user_sessions#new', as: :deprecated_new_spree_user_session, deprecated_route: true
36+
match '/user/spree_user/logout' => 'user_sessions#destroy', via: Devise.sign_out_via, as: :deprecated_destroy_spree_user_session, deprecated_route: true
37+
match '/logout' => 'user_sessions#destroy', via: Devise.sign_out_via, as: :destroy_spree_user_session, deprecated_route: true
38+
post '/user/spree_user/sign_in' => 'user_sessions#create', as: :deprecated_spree_user_session, deprecated_route: true
39+
post '/login' => 'user_sessions#create', as: :spree_user_session, deprecated_route: true
40+
41+
get '/user/spree_user/sign_up' => 'user_registrations#new', as: :deprecated_new_spree_user_registration, deprecated_route: true
42+
get '/signup' => 'user_registrations#new', as: :new_spree_user_registration, deprecated_route: true
43+
post '/user/spree_user' => 'user_registrations#create', as: nil, deprecated_route: true
44+
get '/user/spree_user/cancel' => 'user_registrations#cancel', as: :cancel_spree_user_registration, deprecated_route: true
45+
get '/user/spree_user/edit' => 'user_registrations#edit', as: :edit_spree_user_registration, deprecated_route: true
46+
delete '/user/spree_user' => 'user_registrations#destroy', as: nil, deprecated_route: true
47+
match '/user/spree_user' => 'user_registrations#update', as: :spree_user_registration, via: [:patch, :put], deprecated_route: true
48+
49+
# Custom devise routes
50+
get '/login', to: 'user_sessions#new', as: :login
51+
post '/login', to: 'user_sessions#create', as: :create_new_session
52+
match '/logout', to: 'user_sessions#destroy', via: Devise.sign_out_via, as: :logout
53+
get '/password/recover', to: 'user_passwords#new', as: :recover_password
54+
get '/password/change', to: 'user_passwords#edit', as: :edit_password
55+
put '/password/change', to: 'user_passwords#update', as: :update_password
56+
post '/password/recover', to: 'user_passwords#create', as: :reset_password
57+
get '/signup', to: 'user_registrations#new', as: :signup
58+
post '/signup', to: 'user_registrations#create', as: :registration
59+
get '/confirm', to: 'user_confirmations#show', as: :confirmation if Spree::Auth::Config[:confirmable]
3260
end
3361

3462
get '/checkout/registration', to: 'checkout#registration', as: :checkout_registration

spec/controllers/spree/user_passwords_controller_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
it 'redirects to the new session path' do
1111
get :edit
1212
expect(response).to redirect_to(
13-
'http://test.host/user/spree_user/sign_in'
13+
'http://test.host/login'
1414
)
1515
end
1616

spec/features/checkout_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
# Need to do this now because the token stored in the DB is the encrypted version
112112
# The 'plain-text' version is sent in the email and there's one way to get that!
113113
reset_password_email = ActionMailer::Base.deliveries.first
114-
token_url_regex = /\/user\/spree_user\/password\/edit\?reset_password_token=(.*)$/
114+
token_url_regex = %r{/password/change\?reset_password_token=(.*)$}
115115
token = token_url_regex.match(reset_password_email.body.to_s)[1]
116116

117117
visit spree.edit_spree_user_password_path(reset_password_token: token)

spec/mailers/user_mailer_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
context 'body includes' do
3333
it 'password reset url' do
34-
expect(@message.body.raw_source).to include "http://#{store.url}/user/spree_user/password/edit"
34+
expect(@message.body.raw_source).to include "http://#{store.url}/password/change"
3535
end
3636
end
3737
end

0 commit comments

Comments
 (0)