Sha256: 7fc9c1aa8ddbf6db5cd30380b99ac471153628e95268e803c2c45c0d6e0498f3

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 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], 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
      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.3.5 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-2.3.4 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-2.3.3 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-2.3.2 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-2.3.1 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt
authentication-zero-2.3.0 lib/generators/authentication/templates/controllers/api/password_resets_controller.rb.tt