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

Make the "remember me" option work as intended #5303

Merged
merged 1 commit into from
Nov 13, 2024
Merged
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
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