Sha256: 1964a881faccd2715e4d57515c9e1ab3d003b488100c445646527e489d55c9be

Contents?: true

Size: 971 Bytes

Versions: 6

Compression:

Stored size: 971 Bytes

Contents

class PasswordsController < ApplicationController
  allow_unauthenticated_access
  before_action :set_user_by_token, only: %i[ edit update ]

  def new
  end

  def create
    if user = User.find_by(email_address: params[:email_address])
      PasswordsMailer.reset(user).deliver_later
    end

    redirect_to new_session_path, notice: "Password reset instructions sent (if user with that email address exists)."
  end

  def edit
  end

  def update
    if @user.update(params.permit(:password, :password_confirmation))
      redirect_to new_session_path, notice: "Password has been reset."
    else
      redirect_to edit_password_path(params[:token]), alert: "Passwords did not match."
    end
  end

  private
    def set_user_by_token
      @user = User.find_by_password_reset_token!(params[:token])
    rescue ActiveSupport::MessageVerifier::InvalidSignature
      redirect_to new_password_path, alert: "Password reset link is invalid or has expired."
    end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
railties-8.0.2 lib/rails/generators/rails/authentication/templates/app/controllers/passwords_controller.rb.tt
tm_lyn-0.1.0 app/controllers/passwords_controller.rb
railties-8.0.1 lib/rails/generators/rails/authentication/templates/app/controllers/passwords_controller.rb.tt
railties-8.0.0.1 lib/rails/generators/rails/authentication/templates/app/controllers/passwords_controller.rb.tt
railties-8.0.0 lib/rails/generators/rails/authentication/templates/app/controllers/passwords_controller.rb.tt
railties-8.0.0.rc2 lib/rails/generators/rails/authentication/templates/app/controllers/passwords_controller.rb.tt