Sha256: 5b90fb0f2bd7b12fe569c3a3ada5e39b44b3b7e651428ae62675fb9afb6f33d1

Contents?: true

Size: 1.03 KB

Versions: 14

Compression:

Stored size: 1.03 KB

Contents

class PasswordResetsController < ApplicationController
  def new
  end

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

    if user
      user.prepare_password_reset
      UserMailer.password_reset(user).deliver
      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

14 entries across 7 versions & 1 rubygems

Version Path
authpro-1.1.0 test/rails/dummy/app/controllers/password_resets_controller.rb
authpro-1.1.0 lib/generators/authpro/templates/password_resets_controller.rb
authpro-1.0.1 test/rails/dummy/app/controllers/password_resets_controller.rb
authpro-1.0.1 lib/generators/authpro/templates/password_resets_controller.rb
authpro-1.0.0 lib/generators/authpro/templates/password_resets_controller.rb
authpro-1.0.0 test/rails/dummy/app/controllers/password_resets_controller.rb
authpro-0.9.3 test/rails/dummy/app/controllers/password_resets_controller.rb
authpro-0.9.3 lib/generators/authpro/templates/password_resets_controller.rb
authpro-0.9.2 test/rails/dummy/app/controllers/password_resets_controller.rb
authpro-0.9.2 lib/generators/authpro/templates/password_resets_controller.rb
authpro-0.9.1 test/rails/dummy/app/controllers/password_resets_controller.rb
authpro-0.9.1 lib/generators/authpro/templates/password_resets_controller.rb
authpro-0.9.0 lib/generators/authpro/templates/password_resets_controller.rb
authpro-0.9.0 test/rails/dummy/app/controllers/password_resets_controller.rb