Sha256: 516ec51672fcf44e07b18331e0c405f366767f3c063fdbc615e89a486b3d65f5

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

class Identity::PasswordResetsController < ApplicationController
  skip_before_action :authenticate

  <%- if options.lockable? -%>
  before_action :require_locking, only: :create
  <%- end -%>
  before_action :set_user, only: %i[ edit update ]

  def new
  end

  def edit
  end

  def create
    if @user = User.find_by(email: params[:email], verified: true)
      UserMailer.with(user: @user).password_reset_provision.deliver_later
      redirect_to sign_in_path, notice: "Check your email for reset instructions"
    else
      redirect_to new_identity_password_reset_path, alert: "You can't reset your password until you verify your email"
    end
  end

  def update
    if @user.update(user_params)
      redirect_to sign_in_path, notice: "Your password was reset successfully. Please sign in"
    else
      render :edit, status: :unprocessable_entity
    end
  end

  private
    def set_user
      @user = User.find_signed!(params[:token], purpose: :password_reset)
    rescue
      redirect_to new_identity_password_reset_path, alert: "That password reset link is invalid"
    end

    def user_params
      params.permit(:password, :password_confirmation)
    end
    <%- if options.lockable? %>
    def require_locking
      Locking.lock_on("password_reset_lock:#{request.remote_ip}", wait: 1.hour, attempts: 10) do
        redirect_to new_identity_password_reset_path, alert: "You've exceeded the maximum number of attempts"
      end
    end
    <%- end -%>
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
authentication-zero-2.12.4 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.12.3 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.12.2 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.12.1 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.12.0 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt