Sha256: 53b3b4e506f656b603c8035755eb639e38517ba9cddf42620503d347d18799cc

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

# Register callbacks using Devise internals.

begin
  require "devise"
rescue LoadError # rubocop:disable Lint/HandleExceptions
  # Ignore
end

Immunio::Plugin.load 'Devise' do |plugin|
  if defined? Devise
    module Immunio
      # Hook into password recovery feature to trigger the `framework_password_reset` hook.
      module DeviseRecoverableHooks
        extend ActiveSupport::Concern

        included do
          Immunio::Utils.alias_method_chain self, :send_reset_password_instructions, :immunio
        end

        def send_reset_password_instructions_with_immunio(attributes={})
          Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do
            Immunio.logger.debug { "Devise instrumentation fired for send_reset_password_instructions" }

            recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)

            if recoverable.persisted? # Found
              Immunio.password_reset user_record: recoverable, plugin: 'devise'
            else
              Immunio.failed_password_reset email: recoverable.email, plugin: 'devise'
            end

            Request.pause "plugin", "#{Module.nesting[0]}::#{__method__}" do
              send_reset_password_instructions_without_immunio(attributes)
            end
          end
        end
      end
    end

    Devise::Models::Recoverable::ClassMethods.send :include, Immunio::DeviseRecoverableHooks

    require 'devise/version'
    plugin.loaded! Devise::VERSION
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
immunio-1.1.6 lib/immunio/plugins/devise.rb
immunio-1.1.5 lib/immunio/plugins/devise.rb
immunio-1.1.2 lib/immunio/plugins/devise.rb