Sha256: 9bd73375d88280eaa14a56fd7d4ec18570c40f66acf542f85381e0af1ba9940c

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

class PasswordResetsController < ApplicationController
  skip_before_action :authenticate

  before_action :set_<%= singular_table_name %>, only: :update

  def create
    if @<%= singular_table_name %> = <%= class_name %>.find_by_email(params[:email])
      PasswordMailer.with(<%= singular_table_name %>: @<%= singular_table_name %>).reset.deliver_later
    else
      render json: { error: "Sorry, we didn't recognize that email address" }, status: :not_found
    end
  end

  def update
    if @<%= singular_table_name %>.update(<%= "#{singular_table_name}_params" %>)
      render json: @<%= singular_table_name %>
    else
      render json: @<%= singular_table_name %>.errors, status: :unprocessable_entity
    end
  end

  private
    def set_<%= singular_table_name %>
      @<%= singular_table_name %> = <%= class_name %>.find_signed!(params[:token], purpose: :password_reset)
    rescue ActiveSupport::MessageVerifier::InvalidSignature
      render json: { error: "Your token has expired, please request a new one" }, status: :bad_request
    end

    def <%= "#{singular_table_name}_params" %>
      params.permit(:password, :password_confirmation)
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
authentication-zero-2.1.1 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-2.1.0 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-2.0.0 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt