class Public::PasswordResetsController < ApplicationController
  layout "public"
  
  def create
    p_customer = PCustomer.find_by_email(params[:email])
    if p_customer
      p_customer.send_password_reset 
    
      redirect_to public_my_account_path, :notice => "Un email vous a été envoyé avec les instructions pour la mise à jour."
    else
      render :action => :new
    end
  end

  def edit
    @p_customer = PCustomer.find_by_reset_password_token!(params[:id])
  end

  def update
    @p_customer = PCustomer.find_by_reset_password_token!(params[:id])
    if @p_customer.reset_password_sent_at < 2.hours.ago
      redirect_to new_public_password_reset_path, :alert => "La demande de réinitialisation à expirée."
    elsif @p_customer.update_attributes(params.require(:p_customer).permit(:password, :password_confirmation))
      redirect_to public_my_account_path, :notice => "Le mot de passe à été réinitialisé."
    else
      render :edit
    end
  end
  
end