Class: Fortifier::AuthLog

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/fortifier/auth_log.rb

Constant Summary collapse

BLOCK_COUNT =

an ip is actually blocked at 21 failed attempts

20

Class Method Summary collapse

Class Method Details

.block_ip?(remote_addr) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
# File 'app/models/fortifier/auth_log.rb', line 7

def self.block_ip?(remote_addr)
   # TODO: (DK) remove when no longer needed as reference:
 	# subselect = "SELECT status FROM fortifier_auth_logs WHERE remote_addr = '#{remote_addr}'
 	# 						 AND created_at > '#{Time.now.utc - 10.minutes}' ORDER BY id desc LIMIT #{BLOCK_COUNT}"
 	# count = self.count_by_sql("select count(*) from (#{subselect}) subsel where subsel.status = 0")
BLOCK_COUNT == Fortifier::AuthLog.where(remote_addr: remote_addr, status: 0)
                                     .where('created_at > ?', Time.now.utc-10.minutes)
                                     .limit(BLOCK_COUNT)
                                     .count
end