Guest User

Untitled

a guest
Mar 9th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. --- form from changepass.rhtml ---
  2. <% form_for :user, :action => :changepass, :method => :post do %>
  3. <h3>Change your password</h3>
  4. <fieldset>
  5. <%=@err %>
  6. <%=error_messages_for 'user' %>
  7. <label class="field-password">Current Password &#42;
  8. <input type="password" name="currpass" value="">
  9. </label>
  10. <label class="field-password">New Password &#42;
  11. <%= password_field "user" , "password" %>
  12. </label>
  13. <label class="field-password">Confirm Password &#42;
  14. <%= password_field "user" , "password_confirmation" %>
  15. </label>
  16. <label class="field-submit">
  17. <input type="submit" class="half_right" value="Submit">
  18. </label>
  19. <fieldset>
  20. <% end %>
  21. --- end form from changepass.rhtml ---
  22.  
  23. -- action for this form --
  24. def changepass
  25. return unless request.post?
  26. user = User.find(self.current_user.id)
  27. if user.authenticated?(params[:currpass])
  28. user.crypted_password = user.encrypt(params[:passwd])
  29. user.save
  30. flash[:note] = "Password updated successfully"
  31. redirect_to :action => 'index'
  32. else
  33. flash[:note] = 'Wrong current password'
  34. redirect_to :action => 'changepass'
  35. end
  36. end
Add Comment
Please, Sign In to add comment