discourse/lib/spam_handler.rb

Failed to ignore revisions in .git-blame-ignore-revs.

32 lines
892 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class SpamHandler
def self.should_prevent_registration_from_ip?(ip_address)
return false if SiteSetting.max_new_accounts_per_registration_ip <= 0
tl2_plus_accounts_with_same_ip = User.where("trust_level >= ?", TrustLevel[2])
2017-07-27 21:20:09 -04:00
.where(ip_address: ip_address.to_s)
.count
return false if tl2_plus_accounts_with_same_ip > 0
staff_members_with_same_ip = Group[:staff].users.human_users
2017-07-27 21:20:09 -04:00
.where(ip_address: ip_address.to_s)
.count
return false if staff_members_with_same_ip > 0
ip_whitelisted = ScreenedIpAddress.is_whitelisted?(ip_address)
return false if ip_whitelisted
tl0_accounts_with_same_ip = User.unscoped
2017-07-27 21:20:09 -04:00
.where(trust_level: TrustLevel[0])
.where(ip_address: ip_address.to_s)
.count
tl0_accounts_with_same_ip >= SiteSetting.max_new_accounts_per_registration_ip
end
end