2019-05-03 08:17:27 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-11-17 12:04:29 +01:00
|
|
|
class SpamHandler
|
|
|
|
def self.should_prevent_registration_from_ip?(ip_address)
|
|
|
|
return false if SiteSetting.max_new_accounts_per_registration_ip <= 0
|
|
|
|
|
2014-11-17 15:02:10 +01:00
|
|
|
tl2_plus_accounts_with_same_ip =
|
|
|
|
User.where("trust_level >= ?", TrustLevel[2]).where(ip_address: ip_address.to_s).count
|
|
|
|
|
|
|
|
return false if tl2_plus_accounts_with_same_ip > 0
|
|
|
|
|
2020-04-27 13:01:43 +08:00
|
|
|
staff_members_with_same_ip =
|
2014-11-21 18:16:06 +01:00
|
|
|
Group[:staff].users.human_users.where(ip_address: ip_address.to_s).count
|
2014-11-21 00:25:44 +01:00
|
|
|
|
|
|
|
return false if staff_members_with_same_ip > 0
|
|
|
|
|
2020-07-27 10:23:54 +10:00
|
|
|
allowed_ip = ScreenedIpAddress.is_allowed?(ip_address)
|
|
|
|
return false if allowed_ip
|
2015-06-02 15:06:45 +05:30
|
|
|
|
2014-11-17 12:04:29 +01:00
|
|
|
tl0_accounts_with_same_ip =
|
2014-11-21 18:16:06 +01:00
|
|
|
User.unscoped.where(trust_level: TrustLevel[0]).where(ip_address: ip_address.to_s).count
|
2014-11-17 12:04:29 +01:00
|
|
|
|
|
|
|
tl0_accounts_with_same_ip >= SiteSetting.max_new_accounts_per_registration_ip
|
|
|
|
end
|
|
|
|
end
|