mirror of
https://github.com/discourse/discourse.git
synced 2025-09-10 12:04:21 +08:00
Add BlockedEmail, to block signups based on email. Track stats of how many times each email address is blocked, and last time it was blocked. Move email validation out of User model and into EmailValidator. Signup form remembers which email addresses have failed and shows validation error on email field.
This commit is contained in:
parent
e25638dab0
commit
5f8a130277
10 changed files with 155 additions and 23 deletions
24
lib/validators/email_validator.rb
Normal file
24
lib/validators/email_validator.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
class EmailValidator < ActiveModel::EachValidator
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
if (setting = SiteSetting.email_domains_whitelist).present?
|
||||
unless email_in_restriction_setting?(setting, value)
|
||||
record.errors.add(attribute, I18n.t(:'user.email.not_allowed'))
|
||||
end
|
||||
elsif (setting = SiteSetting.email_domains_blacklist).present?
|
||||
if email_in_restriction_setting?(setting, value)
|
||||
record.errors.add(attribute, I18n.t(:'user.email.not_allowed'))
|
||||
end
|
||||
end
|
||||
if record.errors[attribute].blank? and BlockedEmail.should_block?(value)
|
||||
record.errors.add(attribute, I18n.t(:'user.email.blocked'))
|
||||
end
|
||||
end
|
||||
|
||||
def email_in_restriction_setting?(setting, value)
|
||||
domains = setting.gsub('.', '\.')
|
||||
regexp = Regexp.new("@(#{domains})", true)
|
||||
value =~ regexp
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue