Sha256: 37ee3ed26f03fcd67a3a24d06108c8af9210156f58cf6a811135b0cf576c6621

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

class Identity::PasswordResetsController < ApplicationController
  skip_before_action :authenticate

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

  def new
  end

  def edit
  end

  def create
    if @user = User.find_by(email: params[:email], verified: true)
      UserMailer.with(user: @user).password_reset.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)
      @token.destroy; 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
      @token = PasswordResetToken.find_signed!(params[:sid]); @user = @token.user
    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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
authentication-zero-2.15.0 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.14.0 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt