about summary refs log tree commit diff
path: root/app/lib/email_validator.rb
diff options
context:
space:
mode:
authorEugen <eugen@zeonfederated.com>2017-04-05 03:20:37 +0200
committerGitHub <noreply@github.com>2017-04-05 03:20:37 +0200
commitaa464aa0d81607696e81b559471b089f4bb2ac11 (patch)
tree41fdf3a2227ce785bbf152d85e57236393509ea4 /app/lib/email_validator.rb
parent41ba74b511916330771c097cd74f3bc07801291f (diff)
parenta23123e49c1449c807538bf75ff5db535a2aadf8 (diff)
Merge branch 'master' into patch-1
Diffstat (limited to 'app/lib/email_validator.rb')
-rw-r--r--app/lib/email_validator.rb17
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