mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-08-18 14:05:26 +00:00
* Increase DNS timeout from 1 second to 5 seconds for MX check 1 seconds is rather short when using a recursive DNS resolver which hasn't got a cached result already available. Use 5 seconds instead, which is the timeout value we use for outgoing HTTP queries. * Add more precise error messages for invalid e-mail addresses
37 lines
913 B
Ruby
37 lines
913 B
Ruby
# frozen_string_literal: true
|
|
|
|
class BlacklistedEmailValidator < ActiveModel::Validator
|
|
def validate(user)
|
|
return if user.valid_invitation?
|
|
|
|
@email = user.email
|
|
|
|
user.errors.add(:email, I18n.t('users.blocked_email_provider')) if blocked_email?
|
|
end
|
|
|
|
private
|
|
|
|
def blocked_email?
|
|
on_blacklist? || not_on_whitelist?
|
|
end
|
|
|
|
def on_blacklist?
|
|
return true if EmailDomainBlock.block?(@email)
|
|
return false if Rails.configuration.x.email_domains_blacklist.blank?
|
|
|
|
domains = Rails.configuration.x.email_domains_blacklist.gsub('.', '\.')
|
|
regexp = Regexp.new("@(.+\\.)?(#{domains})", true)
|
|
|
|
@email =~ regexp
|
|
end
|
|
|
|
def not_on_whitelist?
|
|
return false if Rails.configuration.x.email_domains_whitelist.blank?
|
|
|
|
domains = Rails.configuration.x.email_domains_whitelist.gsub('.', '\.')
|
|
regexp = Regexp.new("@(.+\\.)?(#{domains})$", true)
|
|
|
|
@email !~ regexp
|
|
end
|
|
end
|