Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # lost_password_controller.rb
- def create
- email = params[:email].to_s
- if email.empty? # Blank email
- flash[:error] = 'Enter the email address of the account.'
- render :action => :show and return
- end
- if !email.valid_email? # If email address is not valid
- flash[:error] = 'The email address entered is not a valid email address.'
- render :action => :show and return
- end
- user = User.find_last_known(email) # Returns nil if user is not found
- if user.nil?
- flash[:error] = 'There is no user with that email address.'
- render :action => :show and return
- end
- reset_token = UserPasswordResetToken.new( :user_id => user.id, :destination_url => session[:return_to] )
- if reset_token.save
- LostPasswordMailer.deliver_lost_password( user.email )
- render :action => :success
- else
- raise reset_token.errors.full_messages.join(", ")
- # Couldn't save reset token
- # TODO: keolo - something awesome
- end
- end # create
Add Comment
Please, Sign In to add comment