Sha256: 315be678e65bc6b6e8be8efbb3443eba381bc7da8c2f4e4035f1ea65fdd48304

Contents?: true

Size: 993 Bytes

Versions: 14

Compression:

Stored size: 993 Bytes

Contents

class Identity::PasswordResetsController < ApplicationController
  skip_before_action :authenticate

  before_action :set_user, only: :update
  <%- if options.lockable? -%>
  before_action :require_lock, only: :create
  <%- 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)
      @token.destroy; render json: @user
    else
      render json: @user.errors, status: :unprocessable_entity
    end
  end

  private
    def set_user
      @token = PasswordResetToken.find_signed!(params[:sid]); @user = @token.user
    rescue
      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

14 entries across 14 versions & 1 rubygems

Version Path
authentication-zero-2.16.4 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-2.16.3 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-2.16.2 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-2.16.1 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-2.16.0 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-2.15.9 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-2.15.8 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-2.15.7 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-2.15.6 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-2.15.5 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-2.15.4 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-2.15.3 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-2.15.2 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt
authentication-zero-2.15.1 lib/generators/authentication/templates/controllers/api/identity/password_resets_controller.rb.tt