Guest User

Untitled

a guest
Mar 13th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. # lost_password_controller.rb
  2.  
  3. def create
  4. email = params[:email].to_s
  5.  
  6. if email.empty? # Blank email
  7. flash[:error] = 'Enter the email address of the account.'
  8. render :action => :show and return
  9. end
  10.  
  11. if !email.valid_email? # If email address is not valid
  12. flash[:error] = 'The email address entered is not a valid email address.'
  13. render :action => :show and return
  14. end
  15.  
  16. user = User.find_last_known(email) # Returns nil if user is not found
  17.  
  18. if user.nil?
  19. flash[:error] = 'There is no user with that email address.'
  20. render :action => :show and return
  21. end
  22.  
  23. reset_token = UserPasswordResetToken.new( :user_id => user.id, :destination_url => session[:return_to] )
  24.  
  25. if reset_token.save
  26. LostPasswordMailer.deliver_lost_password( user.email )
  27. render :action => :success
  28. else
  29. raise reset_token.errors.full_messages.join(", ")
  30. # Couldn't save reset token
  31. # TODO: keolo - something awesome
  32. end
  33. end # create
Add Comment
Please, Sign In to add comment