Sha256: 255653acb0ac11e88e8a901898a5f63d74f746861b7825b7ff814d03a93827e7

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

class Admin::PasswordResetsController < Admin::BaseController
  skip_before_action :authenticate

  before_action :set_user, only: %i[ edit update ]

  layout "admin/authentication"

  def new
  end

  def edit
  end

  def create
    if @user = Admin::User.find_by(email: params[:email])
      Admin::UserMailer.with(user: @user).password_reset.deliver_later
      redirect_to admin_sign_in_path, notice: "Check your email for reset instructions"
    else
      redirect_to new_admin_password_reset_path, alert: "Sorry, we didn't recognize that email address"
    end
  end

  def update
    if @user.update(user_params)
      redirect_to admin_sign_in_path, notice: "Your password was reset successfully. Please sign in"
    else
      redirect_to edit_admin_password_reset_path(token: params[:token]), alert: @user.errors.first.full_message
    end
  end

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
administration-zero-0.0.17 lib/generators/admin/install/templates/controllers/admin/password_resets_controller.rb
administration-zero-0.0.16 lib/generators/admin/install/templates/controllers/admin/password_resets_controller.rb
administration-zero-0.0.15 lib/generators/admin/install/templates/controllers/admin/password_resets_controller.rb