class PasswordResetsController

Public Instance Methods

create() click to toggle source
# File app/controllers/password_resets_controller.rb, line 5
def create
  if params[:email].blank?
    flash[:notice] = "Please enter an email address"
    return render(:new)
  end
  
  @email = params[:email].strip
  @people = Person.all(:conditions => [ "email = ? and login is not null and login != ''", @email ])
  if @people.any?
    Person.deliver_password_reset_instructions!(@people)
    flash[:notice] = "Please check your email. We've sent you password reset instructions."
    redirect_to new_person_session_url(secure_redirect_options)
  else
    flash[:notice] = "Can't find anyone with this email address"
    render :new
  end
end
update() click to toggle source
# File app/controllers/password_resets_controller.rb, line 23
def update
  @person.password = params[:person][:password]
  @person.password_confirmation = params[:person][:password_confirmation]
  
  if @person.password.blank? || @person.password_confirmation.blank?
    flash[:warn] = "Please provide a new password and confirmation"
    @person.errors.add(:password, "can't be blank") if @person.password.blank?
    @person.errors.add(:password_confirmation, "can't be blank") if @person.password_confirmation.blank?
    return render(:edit)
  end
  
  if @person.save
    @person_session = PersonSession.create(@person)
    flash[:notice] = "Password changed"
    if @person.administrator?
      redirect_back_or_default admin_home_url
    else
      redirect_back_or_default "/account"
    end
  else
    render :edit
  end
end