Commit 7a2c16fa2d71d6bb2a78cc0df2ce607d96109ce3

moved changing of password to a seperate page

Commit diff

app/controllers/accounts_controller.rb

 
1818 render :action => "edit"
1919 end
2020 end
21
22 def password
23 @user = current_user
24 end
25
26 def update_password
27 @user = current_user
28 if User.authenticate(current_user.email, params[:user][:current_password])
29 @user.password = params[:user][:password]
30 @user.password_confirmation = params[:user][:password_confirmation]
31 if @user.save
32 flash[:notice] = "Your password has been changed"
33 redirect_to account_path
34 else
35 render :action => "password"
36 end
37 else
38 flash[:error] = "Your current password doesn't seem to match the one your supplied"
39 render :action => "password"
40 end
41 end
2142end
toggle raw diff

app/models/user.rb

 
88 has_many :comments
99
1010 # Virtual attribute for the unencrypted password
11 attr_accessor :password
11 attr_accessor :password, :current_password
1212
1313 attr_protected :login
1414
toggle raw diff

app/views/accounts/edit.html.erb

 
1414 <%= f.label :url, "url <small>blog etc</small>" -%><br />
1515 <%= f.text_field :url, :class => "text" -%>
1616 </p>
17 <p>
18 <%= f.label :password -%><br />
19 <%= f.password_field :password, :class => "text" -%>
20 </p>
21 <p>
22 <%= f.label :password_confirmation -%><br />
23 <%= f.password_field :password_confirmation, :class => "text" -%>
24 </p>
2517 <%= f.submit "Save" -%>
2618<% end -%>
2719
2820<% content_for :submenu do -%>
2921 <ul>
3022 <li><%= link_to "&#x2190; My account", account_path -%></li>
23 <li><%= link_to "&#x2192; Change password", password_account_path -%></li>
3124 </ul>
3225<% end -%>
toggle raw diff

app/views/accounts/password.html.erb

 
1<h1>Edit your account</h1>
2<%= error_messages_for :user -%>
3
4<% form_for @user, :url => update_password_account_path, :method => :put do |f| -%>
5 <p>
6 <%= f.label :current_password -%><br />
7 <%= f.password_field :current_password, :class => "text" -%>
8 </p>
9 <p>
10 <%= f.label :password, "New password" -%><br />
11 <%= f.password_field :password, :class => "text" -%>
12 </p>
13 <p>
14 <%= f.label :password_confirmation, "New password confirmation" -%><br />
15 <%= f.password_field :password_confirmation, :class => "text" -%>
16 </p>
17 <%= f.submit "Change password" -%>
18<% end -%>
19
20<% content_for :submenu do -%>
21 <ul>
22 <li><%= link_to "&#x2190; My account", account_path -%></li>
23 <li><%= link_to "&#x2190; Edit details", edit_account_path -%></li>
24 </ul>
25<% end -%>
toggle raw diff

config/routes.rb

 
2020
2121 map.root :controller => "site", :action => "index"
2222
23 map.resource :account do |account|
23 map.resource :account, :member => {:password => :get, :update_password => :put} do |account|
2424 account.resources :keys
2525 end
2626 map.resources :users
toggle raw diff

spec/controllers/accounts_controller_spec.rb

 
2727 put :update, :user => {:password => "fubar", :password_confirmation => "fubar"}
2828 flash[:notice].should_not be(nil)
2929 response.should redirect_to(account_path)
30 end
31
32 it "GET /account/password is a-ok" do
33 get :password
34 response.should be_success
35 assigns[:user].should == users(:johan)
36 end
37
38 it "PUT /account/update_password updates password if old one matches" do
39 put :update_password, :user => {
40 :current_password => "test",
41 :password => "fubar",
42 :password_confirmation => "fubar" }
43 response.should redirect_to(account_path)
44 flash[:notice].should match(/Your password has been changed/i)
3045 User.authenticate(users(:johan).email, "fubar").should == users(:johan)
3146 end
47
48 it "PUT /account/update_password does not update password if old one is wrong" do
49 put :update_password, :user => {
50 :current_password => "notthecurrentpassword",
51 :password => "fubar",
52 :password_confirmation => "fubar" }
53 flash[:notice].should == nil
54 flash[:error].should match(/doesn't seem to match/)
55 response.should render_template("accounts/password")
56 User.authenticate(users(:johan).email, "test").should == users(:johan)
57 User.authenticate(users(:johan).email, "fubar").should == nil
58 end
3259
3360end
toggle raw diff