Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
make it possible to disable rememberMe.
Browse files Browse the repository at this point in the history
The remember me functionality can be disabled completely by setting:

```yaml
ticket_granting_ticket:
  lifetime_long_term: -1
```

This does not only remove the "remember me" checkbox from the login
screen but also makes the `SessionsController` ignore any posted
rememberMe param.
  • Loading branch information
senny committed May 12, 2016
1 parent 1488c37 commit e9ce5bd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/controllers/casino/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def create
if !validation_result
show_login_error I18n.t('login_credential_acceptor.invalid_login_credentials')
else
sign_in(validation_result, long_term: params[:rememberMe], credentials_supplied: true)
long_term = remember_me_enabled? && params[:rememberMe]
sign_in(validation_result, long_term: long_term, credentials_supplied: true)
end
end

Expand Down
4 changes: 4 additions & 0 deletions app/helpers/casino/sessions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def sign_out
cookies.delete :tgt
end

def remember_me_enabled?
CASino.config.ticket_granting_ticket[:lifetime_long_term] != -1
end

private
def handle_signed_in(tgt, options = {})
if tgt.awaiting_two_factor_authentication?
Expand Down
7 changes: 4 additions & 3 deletions app/views/casino/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
<%= text_field_tag :username, params[:username], autofocus:true %>
<%= label_tag :password, t('login.label_password') %>
<%= password_field_tag :password %>
<%= label_tag :rememberMe do %>
<%= check_box_tag :rememberMe, 1, params[:rememberMe] %> <%= t('login.label_remember_me') %>
<% if remember_me_enabled? %>
<%= label_tag :rememberMe do %>
<%= check_box_tag :rememberMe, 1, params[:rememberMe] %> <%= t('login.label_remember_me') %>
<% end %>
<% end %>
<%= button_tag t('login.label_button'), :class => 'button' %>
<% end %>
</div>
</div>
<%= render 'footer' %>
</div>

11 changes: 11 additions & 0 deletions spec/controllers/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@
tgt = CASino::TicketGrantingTicket.last
tgt.long_term.should == true
end

context 'with remember me disabled' do
before { CASino.config.ticket_granting_ticket[:lifetime_long_term] = -1 }
after { CASino.config.ticket_granting_ticket[:lifetime_long_term] = 864000 }

it 'does not create a long-term ticket-granting ticket' do
post :create, request_options
tgt = CASino::TicketGrantingTicket.last
tgt.long_term.should == false
end
end
end

context 'with two-factor authentication enabled' do
Expand Down
14 changes: 14 additions & 0 deletions spec/features/login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,18 @@
it { should have_button('Login') }
it { should have_text('Incorrect username or password') }
end

context 'with remember me disabled' do
before { CASino.config.ticket_granting_ticket[:lifetime_long_term] = -1 }
after { CASino.config.ticket_granting_ticket[:lifetime_long_term] = 864000 }
before { visit login_path }

it { should_not have_field('rememberMe') }
end

context 'with remember me enabled' do
before { visit login_path }

it { should have_field('rememberMe') }
end
end

0 comments on commit e9ce5bd

Please sign in to comment.