Class: Antispam::Signup

Inherits:
ApplicationRecord show all
Defined in:
app/models/antispam/signup.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.analyze(user_id:, ip:) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'app/models/antispam/signup.rb', line 3

def self.analyze(user_id:, ip:)
  ip_integer = IPAddr.new(ip).to_i rescue 0
   = .where(user_id: user_id).first_or_initialize
  .ip = ip
  .country_code = Iplocator.get_country(ip_integer)
  .number_from_this_ip = .where(ip: ip).count
  .save
  .safe?
end

Instance Method Details

#safe?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/models/antispam/signup.rb', line 23

def safe?
  self.spamscore <= 50
end

#spamscoreObject



12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/antispam/signup.rb', line 12

def spamscore
  spamscore = 50 # Start at a neutral score

  spamscore += 10 if self.country_code.nil? || (self.country_code == 'ZZ')
  spamscore += 10 if self.number_from_this_ip > 5
  spamscore += 10 if self.number_from_this_ip > 10
  spamscore += 10 if Iplocator.countries_suspected_of_spam.include?(self.country_code)
  spamscore -= 10 if self.number_from_this_ip < 2
  spamscore -= 10 if Iplocator.trusted_countries.include?(self.country_code)
  spamscore = [[spamscore, 0].max, 100].min # Clamp to a value between 0 and 100

  spamscore
end