2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-11-17 05:04:29 -06: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 08:02:10 -06:00
|
|
|
tl2_plus_accounts_with_same_ip = User.where("trust_level >= ?", TrustLevel[2])
|
2014-11-21 11:16:06 -06:00
|
|
|
.where(ip_address: ip_address.to_s)
|
2014-11-17 08:02:10 -06:00
|
|
|
.count
|
|
|
|
|
|
|
|
return false if tl2_plus_accounts_with_same_ip > 0
|
|
|
|
|
2020-04-27 00:01:43 -05:00
|
|
|
staff_members_with_same_ip = Group[:staff].users.human_users
|
2014-11-21 11:16:06 -06:00
|
|
|
.where(ip_address: ip_address.to_s)
|
2014-11-20 17:25:44 -06:00
|
|
|
.count
|
|
|
|
|
|
|
|
return false if staff_members_with_same_ip > 0
|
|
|
|
|
2015-06-02 04:36:45 -05:00
|
|
|
ip_whitelisted = ScreenedIpAddress.is_whitelisted?(ip_address)
|
|
|
|
return false if ip_whitelisted
|
|
|
|
|
2014-11-17 05:04:29 -06:00
|
|
|
tl0_accounts_with_same_ip = User.unscoped
|
|
|
|
.where(trust_level: TrustLevel[0])
|
2014-11-21 11:16:06 -06:00
|
|
|
.where(ip_address: ip_address.to_s)
|
2014-11-17 05:04:29 -06:00
|
|
|
.count
|
|
|
|
|
|
|
|
tl0_accounts_with_same_ip >= SiteSetting.max_new_accounts_per_registration_ip
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|