Guest User

Untitled

a guest
Oct 24th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #view/edit
  2. <h1>Change My Password</h1>
  3. <% form_for @user, :url => password_reset_path, :method => :put do |f| %>
  4. <%= f.error_messages %>
  5. <%= f.label :password %><br />
  6. <%= f.password_field :password %><br />
  7. <br />
  8. <%= f.label :password_confirmation %><br />
  9. <%= f.password_field :password_confirmation %><br />
  10. <br />
  11. <%= f.submit "Update my password and log me in" %>
  12. <% end %>
  13. ~
  14.  
  15. #controller
  16. class PasswordResetsController < ApplicationController
  17. skip_before_filter :authenticate
  18. before_filter :load_user_using_perishable_token, :only => [:edit, :update]
  19. def create
  20. @user = User.find_by_email(params[:email])
  21. if @user
  22. @user.deliver_password_reset_instructions!
  23. redirect_to pw_success_url
  24. else
  25. redirect_to pw_failure_url
  26. end
  27. end
  28.  
  29. def update
  30. puts "*********Made it to update************"
  31. @user.password = params[:user][:password]
  32. @user.password_confirmation = params[:user][:password_confirmation]
  33. if @user.save
  34. redirect_to login_url
  35. else
  36. render :action => :edit
  37. end
  38. end
  39. private
  40. def load_user_using_perishable_token
  41. @user = User.find_using_perishable_token(params[:id])
  42. unless @user
  43. flash[:notice] = "We're sorry, but we could not locate your account. " +
  44. "If you are having issues try copying and pasting the URL " +
  45. "from your email into your browser or restarting the " +
  46. "reset password process."
  47. redirect_to login_url
  48. end
  49. end
  50. end
Add Comment
Please, Sign In to add comment