log_logins 1.0.1 → 1.0.2

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
  SHA256:
3
- metadata.gz: 581e8265dfc64a46c6de15e6c749d8c077ba70ee16a8f6e818308fc8efb4c4c0
4
- data.tar.gz: 56f013a4cb2cd1fb874521870750aebc50781310fec99f9345aa702c4ffefb2c
3
+ metadata.gz: 1f3655e03a98292ce6a41e5b0959a1868ad68309673582e009b5cd8135dcadab
4
+ data.tar.gz: 3075213d75edd56880de2afe1e9f6439bc7b3925d84380cfa94fcaa1aa80e1d1
5
5
  SHA512:
6
- metadata.gz: 130450acaef54354b45a9f02f5ef30b1e83c725022781f5a8cd8d2326f94aab73580ddc552075329dd50e5d1077a7b31f4615245cf58b9f371dcb9ba7aad7c44
7
- data.tar.gz: 396c2c8631f477521e22317c3600978f6d803baa38d932fdcfebf67510034110dcfbbda482dd700eb6e4520009c6c47c5abf7569edfdff04b385698b465833bd
6
+ metadata.gz: 961d975520465a29cae7a60fd3fd1d6bde72a45fc2edfd2b27dbabb06f74431c2610fe16c1913bdc9f4964f40f877cfc8c3f063bedcf3d678d179001bb62ebf1
7
+ data.tar.gz: d834bad436326730e642f86e97009ba8e150df5a0d1844366633bdbb3ddbc9f403532f95283afc13c0dc00cefde718919f1754f2a0bc55fa9c8d689aecc8159c
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -0,0 +1,8 @@
1
+ class AddAdditionalIndexes < ActiveRecord::Migration[4.2]
2
+
3
+ def change
4
+ add_index :login_events, [:user_id, :id]
5
+ add_index :login_events, [:ip, :id], :length => {:ip => 50}
6
+ end
7
+
8
+ end
@@ -77,7 +77,7 @@ module LogLogins
77
77
  # @return [Boolean]
78
78
  def self.user_blocked?(user)
79
79
  return false unless user.is_a?(ActiveRecord::Base)
80
- last_success = self.success_or_unblock.order(:id => :desc).select(:id).first.try(:id) || 0
80
+ last_success = self.where(:user => user).success_or_unblock.order(:id => :desc).select(:id).first.try(:id) || 0
81
81
  self.failed_in_block_time.where(:user => user).where("id > ?", last_success).count >= LogLogins.config.attempts_before_block
82
82
  end
83
83
 
@@ -87,9 +87,20 @@ module LogLogins
87
87
  # @return [Boolean]
88
88
  def self.ip_blocked?(ip)
89
89
  return false if ip.nil?
90
- last_success = self.success_or_unblock.order(:id => :desc).select(:id).first.try(:id) || 0
90
+ last_success = self.where(:user => nil, :ip => ip.to_s).success_or_unblock.order(:id => :desc).select(:id).first.try(:id) || 0
91
91
  self.failed_in_block_time.where(:user => nil, :ip => ip.to_s).where("id > ?", last_success).count >= LogLogins.config.attempts_before_block_on_ip
92
92
  end
93
93
 
94
+ # Delete old login data
95
+ #
96
+ # @return [Integer] the number of removed items
97
+ def self.prune(max_age = 6.months)
98
+ if last_to_keep = self.where("created_at <= ?", max_age.ago).order(:created_at => :desc).first.try(:id)
99
+ self.where("id <= ?", last_to_keep).delete_all
100
+ else
101
+ 0
102
+ end
103
+ end
104
+
94
105
  end
95
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LogLogins
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_logins
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
@@ -59,6 +59,7 @@ extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
61
  - db/migrate/20180307100300_create_log_logins_events_table.rb
62
+ - db/migrate/20180307161400_add_additional_indexes.rb
62
63
  - lib/log_logins.rb
63
64
  - lib/log_logins/config.rb
64
65
  - lib/log_logins/engine.rb
metadata.gz.sig CHANGED
Binary file