Sha256: dc73af6efa56d4a618b100cc6a58b7753f03253b09c9ca39b85f9936b57f20d4

Contents?: true

Size: 1.32 KB

Versions: 17

Compression:

Stored size: 1.32 KB

Contents

class Identity::PasswordResetsController < ApplicationController
  skip_before_action :authenticate

  <%- if options.lockable? -%>
  before_action :require_lock, 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)
      send_password_reset_email
      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)
      revoke_tokens; 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 StandardError
      redirect_to new_identity_password_reset_path, alert: "That password reset link is invalid"
    end

    def user_params
      params.permit(:password, :password_confirmation)
    end

    def send_password_reset_email
      UserMailer.with(user: @user).password_reset.deliver_later
    end

    def revoke_tokens
      @user.password_reset_tokens.delete_all
    end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
authentication-zero-2.16.36 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.35 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.34 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.33 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.32 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.31 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.30 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.29 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.28 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.27 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.26 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.25 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.24 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.23 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.22 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.21 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt
authentication-zero-2.16.20 lib/generators/authentication/templates/controllers/html/identity/password_resets_controller.rb.tt