Sha256: 89b8a6f1108ee2496664f5b26eeebdd384623541ca41cf687df82623b6ee9692

Contents?: true

Size: 1005 Bytes

Versions: 2

Compression:

Stored size: 1005 Bytes

Contents

class PasswordResetsController < ApplicationController
  def new
  end

  def create
    user = User.find_by email: params[:email]

    if user
      user.send_password_reset
      redirect_to root_url, notice: "Email sent with password reset instructions."
    else
      flash.now.alert = "We could not find anyone with that email address."
      render "new"
    end
  end

  def edit
    @user = User.find_by! password_reset_token: params[:id]
  end

  def update
    @user = User.find_by! password_reset_token: params[:id]
    if @user.password_reset_sent_at < 20.hours.ago
      redirect_to new_password_reset_path, alert: "Password reset has expired."
    elsif @user.update_attributes(user_params)
      redirect_to root_url, notice: "Password has been reset."
    else
      render :edit
    end
  end

  private
  # Never trust parameters from the scary internet, only allow the white list through.
  def user_params
    params.require(:user).permit(:password, :password_confirmation)
  end
end

Version data entries

2 entries across 1 versions & 1 rubygems

Version Path
authpro-0.1.0 lib/generators/authpro/templates/password_resets_controller.rb
authpro-0.1.0 test/rails/dummy/app/controllers/password_resets_controller.rb