Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log out via POST request #303

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
devise_scope :spree_user do
get '/login' => 'user_sessions#new', :as => :login
post '/login' => 'user_sessions#create', :as => :create_new_session
get '/logout' => 'user_sessions#destroy', :as => :logout
post '/logout' => 'user_sessions#destroy', :as => :logout
get '/signup' => 'user_registrations#new', :as => :signup
post '/signup' => 'user_registrations#create', :as => :registration
get '/password/recover' => 'user_passwords#new', :as => :recover_password
Expand All @@ -41,7 +41,7 @@
get '/authorization_failure', :to => 'user_sessions#authorization_failure', :as => :unauthorized
get '/login' => 'user_sessions#new', :as => :login
post '/login' => 'user_sessions#create', :as => :create_new_session
get '/logout' => 'user_sessions#destroy', :as => :logout
post '/logout' => 'user_sessions#destroy', :as => :logout
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/views/backend/spree/layouts/admin/_login_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<%= link_to Spree.t(:account), spree.edit_user_path(spree_current_user), class: "btn btn-default btn-flat" %>
</div>
<div class="pull-right" data-hook="user-logout-link">
<%= link_to Spree.t(:logout), spree.admin_logout_path, class: "btn btn-default btn-flat" %>
<%= link_to Spree.t(:logout), spree.admin_logout_path, method: :post, class: "btn btn-default btn-flat" %>
</div>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion lib/views/frontend/spree/shared/_login_bar.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if spree_current_user %>
<li><%= link_to Spree.t(:my_account), spree.account_path %></li>
<li><%= link_to Spree.t(:logout), spree.logout_path %></li>
<li><%= link_to Spree.t(:logout), spree.logout_path, method: :post %></li>
<% else %>
<li id="link-to-login"><%= link_to Spree.t(:login), spree.login_path %></li>
<% end %>
8 changes: 8 additions & 0 deletions spec/features/admin/sign_out_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@
expect(page).to have_button 'Login'
expect(page).not_to have_text 'Logout'
end

scenario 'does not allow logging out by a GET request' do
expect do
visit spree.admin_logout_path
end.to raise_error(ActionController::RoutingError)
visit spree.admin_login_path
expect(page).to have_text('You are already signed in')
end
end
8 changes: 8 additions & 0 deletions spec/features/sign_out_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@
expect(page).to have_text 'Login'
expect(page).not_to have_text 'Logout'
end

scenario 'restrict signing out by a GET request' do
expect do
visit spree.logout_path
end.to raise_error(ActionController::RoutingError)
visit spree.login_path
expect(page).to have_text('You are already signed in')
end
end