From: Tom Hughes Date: Tue, 5 Nov 2024 18:42:20 +0000 (+0000) Subject: Make the "remember me" option work as intended X-Git-Tag: live~21^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/a42b6546060227fce391c54557d7383f0291f410 Make the "remember me" option work as intended --- diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index a3e6f42f0..abbaf5e92 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -20,7 +20,7 @@ class SessionsController < ApplicationController end def create - session[:remember_me] ||= params[:remember_me] + session[:remember_me] = params[:remember_me] == "yes" referer = safe_referer(params[:referer]) if params[:referer] diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 9d05d4af8..c2d96b63c 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -40,7 +40,7 @@ <%= f.password_field :password, :autocomplete => "on", :tabindex => 2, :value => "", :skip_label => true %> <%= f.form_group do %> - <%= f.check_box :remember_me, { :label => t(".remember"), :tabindex => 3, :checked => (params[:remember_me] == "yes") }, "yes" %> + <%= f.check_box :remember_me, { :label => t(".remember"), :tabindex => 3, :checked => (params[:remember_me] == "true") }, "yes" %> <% end %>
diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb index 914a4ab56..f490b748c 100644 --- a/test/controllers/sessions_controller_test.rb +++ b/test/controllers/sessions_controller_test.rb @@ -54,6 +54,24 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest assert_redirected_to root_path end + def test_login_remembered + user = create(:user) + + post login_path, :params => { :username => user.display_name, :password => "test", :remember_me => "yes" } + assert_redirected_to root_path + + assert_equal 28 * 86400, session[:_remember_for] + end + + def test_login_not_remembered + user = create(:user) + + post login_path, :params => { :username => user.display_name, :password => "test", :remember_me => "0" } + assert_redirected_to root_path + + assert_nil session[:_remember_for] + end + def test_logout_without_referer post logout_path assert_redirected_to root_path