effective_logging 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ffec40703187b420ab31ea83ccb1c7d54f480c5
4
- data.tar.gz: 1d61908e31c154fb6b61250f6b9ca8a521eae13f
3
+ metadata.gz: 7403fe3327b28b8f84977469b565964981bc0608
4
+ data.tar.gz: 41d3d0730dfcc1ea9618bab4e9e39c098ad50a52
5
5
  SHA512:
6
- metadata.gz: 9dcf971011fb02748255f89d58f5c534bbe7a5b8c694e39077589db39775efc4f41ee57a74b6590cefda73dcba32fb1b7453adfc5afdcbd420338ff1ea47b316
7
- data.tar.gz: 29e2c73f69b919bb725ea5a15727dd8667017f66754e5b208ae77cbd0a4d9f3179226ad0ab8fdbfb233533a6a7c02d05f1a030649ff5243fa27d94cd6435ed6e
6
+ metadata.gz: fd177c572ef4d57f23dbfc9ac8d5d38bea1a56b3476f99955a52753241aabdc0dcb27d27ea6882c7e58e3733dd47e48ad7331d24eecb02a63a3b62b8986bdc07
7
+ data.tar.gz: 31f23fec3d1b5347423fe0b539c7b874ea0af6ba5797b10f2a37325d72aa35536d7bc4eb0be043d083e58b0a019f9dfe8ae79c3edd47aa207dcfce31ecf32052
data/README.md CHANGED
@@ -99,9 +99,9 @@ This behaviour can be disabled in the config/initializers/effective_logging.rb i
99
99
  If the TO email address match a User, the :user will be set appropriately.
100
100
 
101
101
 
102
- ### Automatic Logging of User Logins
102
+ ### Automatic Logging of User Login and Logout
103
103
 
104
- Any successful User logins via Devise will be automatically logged.
104
+ Any successful User logins and logouts via Devise will be automatically logged.
105
105
 
106
106
  This behaviour can be disabled in the config/initializers/effective_logging.rb initializer.
107
107
 
@@ -35,12 +35,9 @@ module EffectiveLogging
35
35
  if EffectiveLogging.user_logins_enabled == true
36
36
  ActiveSupport.on_load :active_record do
37
37
  if defined?(Devise)
38
- User.instance_eval do
39
- alias_method :original_after_database_authentication, :after_database_authentication
40
- define_method(:after_database_authentication) { Effective::UserLogger.successful_login(self) ; original_after_database_authentication() }
41
- end
38
+ EffectiveLogging::UserLogger.create_warden_hooks()
42
39
  else
43
- raise ArgumentError.new("EffectiveLogging.user_logins_enabled only works with Devise and a user class defined as User")
40
+ raise ArgumentError.new("EffectiveLogging.user_logins_enabled only works with Devise")
44
41
  end
45
42
  end
46
43
  end
@@ -0,0 +1,37 @@
1
+ module EffectiveLogging
2
+ class UserLogger
3
+ def self.create_warden_hooks
4
+ Warden::Manager.after_authentication do |user, warden, opts|
5
+ EffectiveLogger.success('user login',
6
+ :user => user,
7
+ :ip => warden.request.ip.presence,
8
+ :referrer => warden.request.referrer,
9
+ :user_agent => warden.request.user_agent
10
+ )
11
+ end
12
+
13
+ Warden::Manager.before_logout do |user, warden, opts|
14
+ if user.respond_to?(:timedout?) && user.respond_to?(:timeout_in)
15
+ scope = opts[:scope]
16
+ last_request_at = (warden.request.session["warden.#{scope}.#{scope}.session"]['last_request_at'] rescue Time.zone.now)
17
+
18
+ # As per Devise
19
+ if last_request_at.is_a? Integer
20
+ last_request_at = Time.at(last_request_at).utc
21
+ elsif last_request_at.is_a? String
22
+ last_request_at = Time.parse(last_request_at)
23
+ end
24
+
25
+ if user.timedout?(last_request_at) && !warden.request.env['devise.skip_timeout']
26
+ EffectiveLogger.success('user logout', :user => user, :timedout => true)
27
+ else
28
+ EffectiveLogger.success('user logout', :user => user)
29
+ end
30
+ else # User does not respond to timedout
31
+ EffectiveLogger.success('user logout', :user => user)
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module EffectiveLogging
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "effective_logging/engine"
2
2
  require "effective_logging/version"
3
3
  require "effective_logging/log_page_views"
4
+ require "effective_logging/user_logger"
4
5
 
5
6
  module EffectiveLogging
6
7
  # The following are all valid config keys
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-08 00:00:00.000000000 Z
11
+ date: 2014-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -99,7 +99,6 @@ files:
99
99
  - app/models/effective/access_denied.rb
100
100
  - app/models/effective/datatables/logs.rb
101
101
  - app/models/effective/log.rb
102
- - app/models/effective/user_logger.rb
103
102
  - app/models/effective_logger.rb
104
103
  - app/views/active_admin/effective_logging/logs/index.html.haml
105
104
  - app/views/active_admin/effective_logging/logs/show.html.haml
@@ -114,6 +113,7 @@ files:
114
113
  - lib/effective_logging/email_logger.rb
115
114
  - lib/effective_logging/engine.rb
116
115
  - lib/effective_logging/log_page_views.rb
116
+ - lib/effective_logging/user_logger.rb
117
117
  - lib/effective_logging/version.rb
118
118
  - lib/generators/effective_logging/install_generator.rb
119
119
  - lib/generators/templates/README
@@ -1,7 +0,0 @@
1
- module Effective
2
- class UserLogger
3
- def self.successful_login(user)
4
- EffectiveLogger.success("user login from #{user.try(:current_sign_in_ip) || 'unknown IP'}", :user => user)
5
- end
6
- end
7
- end