cartodb-4.42/config/initializers/email_address.rb

22 lines
619 B
Ruby
Raw Normal View History

2024-04-06 13:25:13 +08:00
EmailAddress::Config.configure(local_format: :conventional, host_validation: Cartodb.config[:disable_email_mx_check] ? :syntax : :mx )
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return unless value
if value.is_a?(Array)
value.each { |v| validate_value(record, attribute, v) }
else
validate_value(record, attribute, value)
end
end
private
def validate_value(record, attribute, value)
unless EmailAddress.valid?(value)
record.errors[attribute] << (options[:message] || "#{value} is not a valid email")
end
end
end