Sha256: bf00b9f958b66b7d7938585a480988ef7c34f291c9aaae37fd289ec085e541d0

Contents?: true

Size: 931 Bytes

Versions: 1

Compression:

Stored size: 931 Bytes

Contents

# frozen_string_literal: true

class PasswordResetsController < ApplicationController
  skip_before_action :authorization_required

  layout "sessions"

  # Form for user to request a password reset
  def new
    @user = MinimalistAuthentication.configuration.user_model.new
  end

  # Send a password update link to users with a verified email
  def create
    if user
      user.regenerate_verification_token
      MinimalistAuthenticationMailer.with(user:).update_password.deliver_now
    end
    # always display notice even if the user was not found to prevent leaking user emails
    redirect_to new_session_path, notice: "Password reset instructions were mailed to #{email}"
  end

  private

  def user
    return unless URI::MailTo::EMAIL_REGEXP.match?(email)

    @user ||= MinimalistAuthentication.configuration.user_model.active.email_verified.find_by(email:)
  end

  def email
    params.dig(:user, :email)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
minimalist_authentication-3.1.0 app/controllers/password_resets_controller.rb