Sha256: 42399cef09184de9ef0dde5e0cd2ab035727316da9ba8599df57c393173462fc

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

class PasswordResetsController < ApplicationController
  before_action :set_<%= singular_table_name %>, only: :update

  skip_before_action :authenticate

  def create
    if @<%= singular_table_name %> = <%= class_name %>.find_by(email: params[:email], verified: true)
      IdentityMailer.with(<%= singular_table_name %>: @<%= singular_table_name %>).password_reset_provision.deliver_later
    else
      render json: { error: "You can't reset your password until you verify your email" }, 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: "That password reset link is invalid" }, status: :bad_request
    end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
authentication-zero-2.2.6 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-2.2.5 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-2.2.4 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-2.2.3 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-2.2.2 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-2.2.1 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt