Skip to content

Commit

Permalink
Add remember-me box to welcome controller and view
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh French committed Jun 26, 2008
1 parent 556710c commit 64f5581
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/admin/welcome_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def login
announce_invalid_user unless self.current_user = User.authenticate(login, password)
end
if current_user
if params[:remember_me]
current_user.remember_me
set_session_cookie
end
redirect_to (session[:return_to] || welcome_url)
session[:return_to] = nil
end
Expand Down
8 changes: 8 additions & 0 deletions app/views/admin/welcome/login.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
input.textbox
font-size: 100%
width: 16em
label.checkbox
float: none
input.checkbox
margin-left: 87px
.buttons
margin-top: 15px
margin-bottom: 20px
Expand All @@ -38,6 +42,10 @@
%p
%label{:for=>"user_password"} Password
= password_field "user", "password", :class => 'textbox', :value => '', :maxlength => 40
%p
= check_box_tag :remember_me, 1, false, :class => 'checkbox'
%label{:for=>"remember_me", :class => 'checkbox'}
%small Remember me
%p.buttons
%input.button{:type=>"submit", :value=>"Login"}/

Expand Down
21 changes: 21 additions & 0 deletions spec/controllers/admin/welcome_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@
response.should render_template("login")
flash[:error].should_not be_nil
end

describe "remember me" do

before do
Radiant::Config.stub!(:[]).with('session_timeout').and_return(2.weeks)
@user = users(:admin)
controller.stub!(:current_user).and_return(@user)
end

after do
post :login, :user => {:login => "admin", :password => "password"}, :remember_me => 1
end

it "should remember user" do
@user.should_receive(:remember_me)
end

it "should set cookie" do
controller.should_receive(:set_session_cookie)
end
end

describe "with a logged-in user" do
before do
Expand Down

0 comments on commit 64f5581

Please sign in to comment.