Guest User

Untitled

a guest
Jun 5th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. # This is action in the controller
  2. #Reset password
  3. def reset
  4. @user = User.find_by_reset_code(params[:reset_code])
  5.  
  6. if request.post?
  7. respond_to do |format|
  8. if @user.update_attributes(params[:user]) #@user.update_attributes(:password => params[:password], :password_confirmation => params[:password_confirmation])
  9. logger.debug("******** Success")
  10. self.current_user = @user
  11. @user.delete_reset_code
  12. flash[:notice] = "Your password was reset successfully."
  13. format.html { redirect_to "/login" }
  14. else
  15. logger.debug("******** Fail")
  16. format.html { render :layout => "login_template", :action => "reset" }
  17. end
  18. end
  19. end
  20.  
  21. end
  22.  
  23. #And here is the view
  24. <div id="reset_box">
  25.  
  26. <h1>Reset your password</h1>
  27.  
  28. <p class="instructions">Type a new password for <%= @user.email %>.</p>
  29.  
  30. <%= custom_error_messages_for @user %>
  31.  
  32. <% form_for :user do |f| %>
  33.  
  34. <p>
  35. <label for="password">Password</label><br />
  36. <%= f.password_field :password %>
  37. </p>
  38.  
  39. <p>
  40. <label for="password">Confirm Password</label><br />
  41. <%= f.password_field :password_confirmation %>
  42. </p>
  43.  
  44. <p class="reset_submit">
  45. <%= submit_tag 'Reset', :class => "login_button" %> or <%= link_to "Cancel", "login" %>
  46. </p>
  47. <% end %>
  48.  
  49. <br clear="all"/>
  50.  
  51. </div>
Add Comment
Please, Sign In to add comment