Sha256: 3fded5e5cd5210622fda4bdb0432dbb9c3fea0db087f08d89b20292dfead7902

Contents?: true

Size: 1.86 KB

Versions: 55

Compression:

Stored size: 1.86 KB

Contents

module EffectiveLogging
  class UserLogger
    def self.create_warden_hooks
      Warden::Manager.after_authentication do |user, warden, opts|
        if EffectiveLogging.sign_in_enabled && !EffectiveLogging.supressed?
          ::EffectiveLogger.sign_in('Sign in', user: user, associated: user, request: warden.request)
        end
      end

      Warden::Manager.after_set_user do |user, warden, opts|
        if EffectiveLogging.sign_in_enabled && !EffectiveLogging.supressed?
          if opts && opts[:event] == :set_user && !opts.key?(:store) # User has just reset their password and signed in
            ::EffectiveLogger.sign_in('Sign in', user: user, associated: user, request: warden.request, notes: 'after password reset')
          end
        end
      end

      Warden::Manager.before_logout do |user, warden, opts|
        if EffectiveLogging.sign_out_enabled && !EffectiveLogging.supressed?
          if user.respond_to?(:timedout?) && user.respond_to?(:timeout_in)
            scope = opts[:scope]
            last_request_at = (warden.request.session["warden.#{scope}.#{scope}.session"]['last_request_at'] rescue Time.zone.now)

            # As per Devise
            if last_request_at.is_a? Integer
              last_request_at = Time.at(last_request_at).utc
            elsif last_request_at.is_a? String
              last_request_at = Time.parse(last_request_at)
            end

            if user.timedout?(last_request_at) && !warden.request.env['devise.skip_timeout']
              ::EffectiveLogger.sign_out('Sign out', user: user, associated: user, timedout: true)
            else
              ::EffectiveLogger.sign_out('Sign out', user: user, associated: user)
            end
          else # User does not respond to timedout
            ::EffectiveLogger.sign_out('Sign out', user: user, associated: user)
          end
        end
      end

    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
effective_logging-4.3.1 lib/effective_logging/user_logger.rb
effective_logging-4.3.0 lib/effective_logging/user_logger.rb
effective_logging-4.2.0 lib/effective_logging/user_logger.rb
effective_logging-4.1.3 lib/effective_logging/user_logger.rb
effective_logging-4.1.2 lib/effective_logging/user_logger.rb
effective_logging-4.1.1 lib/effective_logging/user_logger.rb
effective_logging-4.1.0 lib/effective_logging/user_logger.rb
effective_logging-4.0.0 lib/effective_logging/user_logger.rb
effective_logging-3.5.4 lib/effective_logging/user_logger.rb
effective_logging-3.5.3 lib/effective_logging/user_logger.rb
effective_logging-3.5.2 lib/effective_logging/user_logger.rb
effective_logging-3.5.1 lib/effective_logging/user_logger.rb
effective_logging-3.5.0 lib/effective_logging/user_logger.rb
effective_logging-3.4.1 lib/effective_logging/user_logger.rb
effective_logging-3.4.0 lib/effective_logging/user_logger.rb
effective_logging-3.3.0 lib/effective_logging/user_logger.rb
effective_logging-3.2.3 lib/effective_logging/user_logger.rb
effective_logging-3.2.2 lib/effective_logging/user_logger.rb
effective_logging-3.2.1 lib/effective_logging/user_logger.rb
effective_logging-3.2.0 lib/effective_logging/user_logger.rb