Sha256: e0a5568ac5d2399ba7f667e0f76847eeef3a3bfaa75c626bd3b01e9f2b86f434

Contents?: true

Size: 1017 Bytes

Versions: 4

Compression:

Stored size: 1017 Bytes

Contents

class Identity::PasswordResetsController < ApplicationController
  skip_before_action :authenticate

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

  def edit
    head :no_content
  end

  def create
    if @user = User.find_by(email: params[:email], verified: true)
      UserMailer.with(user: @user).password_reset.deliver_later
    else
      render json: { error: "You can't reset your password until you verify your email" }, status: :bad_request
    end
  end

  def update
    if @user.update(user_params)
      render json: @user
    else
      render json: @user.errors, status: :unprocessable_entity
    end
  end

  private
    def set_user
      @user = User.find_by_token_for!(:password_reset, params[:sid])
    rescue StandardError
      render json: { error: "That password reset link is invalid" }, status: :bad_request
    end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
authentication-zero-3.0.2 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-3.0.1 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-3.0.0 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-3.0.0.alpha1 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt