Skip to content

Commit

Permalink
Merge pull request #5303 from tomhughes/remember-me
Browse files Browse the repository at this point in the history
Make the "remember me" option work as intended
  • Loading branch information
gravitystorm authored Nov 13, 2024
2 parents 6042632 + a42b654 commit fef9ace
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def new
end

def create
session[:remember_me] ||= params[:remember_me]
session[:remember_me] = params[:remember_me] == "yes"

referer = safe_referer(params[:referer]) if params[:referer]

Expand Down
2 changes: 1 addition & 1 deletion app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>

<div class="mb-3">
Expand Down
18 changes: 18 additions & 0 deletions test/controllers/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ def test_login
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
Expand Down

0 comments on commit fef9ace

Please sign in to comment.