Sha256: 7ecd7039371acd59e74d27006f5aef8b162b10e4f9eb7846917a16e6a5057f60

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

class PasswordResetsController < ApplicationController
  before_action :set_<%= singular_table_name %>, only: %i[ edit update ]
  skip_before_action :authenticate

  def edit
    render json: { message: "Open this link in your device" }, status: :not_found
  end

  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: "The email address doesn't exist in our database" }, status: :bad_request
    end
  end

  def update
    if @<%= singular_table_name %>.update(password_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 password_params
      params.require(:<%= singular_table_name %>).permit(:password, :password_confirmation)
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
authentication-zero-0.0.9 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-0.0.8 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-0.0.7 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt