2019-05-03 08:17:27 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-10-21 14:49:51 -04:00
|
|
|
class AllowedIpAddressValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(record, attribute, value)
|
2014-11-17 12:04:29 +01:00
|
|
|
if record.ip_address
|
2023-10-27 15:22:38 +08:00
|
|
|
record.errors.add(attribute, :blocked) if ScreenedIpAddress.should_block?(record.ip_address)
|
2015-06-01 10:16:25 +05:30
|
|
|
if record.trust_level == TrustLevel[0] &&
|
|
|
|
SpamHandler.should_prevent_registration_from_ip?(record.ip_address)
|
2023-10-27 15:22:38 +08:00
|
|
|
record.errors.add(attribute, :max_new_accounts_per_registration_ip)
|
2015-06-01 10:16:25 +05:30
|
|
|
end
|
2013-10-21 14:49:51 -04:00
|
|
|
end
|
|
|
|
end
|
2014-11-17 12:04:29 +01:00
|
|
|
end
|