diff options
author | Eugen <eugen@zeonfederated.com> | 2017-04-05 03:20:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-05 03:20:37 +0200 |
commit | aa464aa0d81607696e81b559471b089f4bb2ac11 (patch) | |
tree | 41fdf3a2227ce785bbf152d85e57236393509ea4 /app/lib/email_validator.rb | |
parent | 41ba74b511916330771c097cd74f3bc07801291f (diff) | |
parent | a23123e49c1449c807538bf75ff5db535a2aadf8 (diff) |
Merge branch 'master' into patch-1
Diffstat (limited to 'app/lib/email_validator.rb')
-rw-r--r-- | app/lib/email_validator.rb | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/app/lib/email_validator.rb b/app/lib/email_validator.rb index 856b8b1f7..06e9375f6 100644 --- a/app/lib/email_validator.rb +++ b/app/lib/email_validator.rb @@ -2,17 +2,30 @@ class EmailValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - return if Rails.configuration.x.email_domains_blacklist.empty? - record.errors.add(attribute, I18n.t('users.invalid_email')) if blocked_email?(value) end private def blocked_email?(value) + on_blacklist?(value) || not_on_whitelist?(value) + end + + def on_blacklist?(value) + return false if Rails.configuration.x.email_domains_blacklist.blank? + domains = Rails.configuration.x.email_domains_blacklist.gsub('.', '\.') regexp = Regexp.new("@(.+\\.)?(#{domains})", true) value =~ regexp end + + def not_on_whitelist?(value) + return false if Rails.configuration.x.email_domains_whitelist.blank? + + domains = Rails.configuration.x.email_domains_whitelist.gsub('.', '\.') + regexp = Regexp.new("@(.+\\.)?(#{domains})", true) + + value !~ regexp + end end |