2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-11-17 19:04:29 +08:00
|
|
|
require_dependency "spam_handler"
|
|
|
|
|
2013-10-22 02:49:51 +08:00
|
|
|
class AllowedIpAddressValidator < ActiveModel::EachValidator
|
|
|
|
|
|
|
|
def validate_each(record, attribute, value)
|
2014-11-17 19:04:29 +08:00
|
|
|
if record.ip_address
|
2015-06-01 12:46:25 +08:00
|
|
|
if ScreenedIpAddress.should_block?(record.ip_address)
|
2015-06-02 10:05:42 +08:00
|
|
|
record.errors.add(attribute, I18n.t('user.ip_address.blocked'))
|
2014-11-17 19:04:29 +08:00
|
|
|
end
|
2015-06-01 12:46:25 +08:00
|
|
|
if record.trust_level == TrustLevel[0] && SpamHandler.should_prevent_registration_from_ip?(record.ip_address)
|
|
|
|
record.errors.add(attribute, I18n.t('user.ip_address.max_new_accounts_per_registration_ip'))
|
|
|
|
end
|
2013-10-22 02:49:51 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-17 19:04:29 +08:00
|
|
|
end
|