Class: Antispam::Signup
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Antispam::Signup
- 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 signup = Signup.where(user_id: user_id).first_or_initialize signup.ip = ip signup.country_code = Iplocator.get_country(ip_integer) signup.number_from_this_ip = Signup.where(ip: ip).count signup.save signup.safe? end |
Instance Method Details
#safe? ⇒ Boolean
23 24 25 |
# File 'app/models/antispam/signup.rb', line 23 def safe? self.spamscore <= 50 end |
#spamscore ⇒ Object
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 |