Guest User

Untitled

a guest
Mar 13th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. def change
  2. # POST /lost_password/:token
  3. reset_token = UserPasswordResetToken.find_by_token( params[:token] )
  4.  
  5. # Check for mismatched passwords
  6. if params[:password] != params[:password_confirmation]
  7. flash[:error] = 'The new passwords did not match.'
  8. render :action => :new and return
  9. end
  10.  
  11. if reset_token.respond_to?( :expires ) && reset_token.expires >= Time.now.utc
  12. user = reset_token.user
  13.  
  14. if user.nil?
  15. # User associated with this reset_token doesn't exist
  16. render :action => :new and return
  17. end
  18.  
  19. user.password = params[:password]
  20. user.password_confirmation = params[:password_confirmation]
  21.  
  22. if user.save
  23. # puts "Changed the password to #{user.password}"
  24. # Redirect to homepage or destination url
  25. flash[:notice] = 'Your password has successfully been changed.'
  26. redirect_to reset_token.destination_url.to_s.empty? ? '/' : reset_token.destination_url.to_s
  27. else
  28. # Couldn't save new password
  29. flash[:error] = "Could not change the new password: #{user.errors.full_messages.join(", ")}"
  30. render :action => :new and return
  31. end
  32. end
Add Comment
Please, Sign In to add comment