Sha256: af336f06ccb56b286c9bee82aacd32ccfb0ca869dde4bed49aaeb77eafa9a073

Contents?: true

Size: 1.21 KB

Versions: 6

Compression:

Stored size: 1.21 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])
      send_password_reset_email
      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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
administration-zero-1.0.4 lib/generators/admin/install/templates/controllers/admin/password_resets_controller.rb
administration-zero-1.0.3 lib/generators/admin/install/templates/controllers/admin/password_resets_controller.rb
administration-zero-1.0.2 lib/generators/admin/install/templates/controllers/admin/password_resets_controller.rb
administration-zero-1.0.1 lib/generators/admin/install/templates/controllers/admin/password_resets_controller.rb
administration-zero-1.0.0 lib/generators/admin/install/templates/controllers/admin/password_resets_controller.rb
administration-zero-0.0.18 lib/generators/admin/install/templates/controllers/admin/password_resets_controller.rb