mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 05:01:44 +08:00
Better checking of blacklisted emails on create and when email is being updated
This commit is contained in:
parent
2204ded099
commit
85f8f8f2d5
|
@ -27,7 +27,7 @@ class User < ActiveRecord::Base
|
|||
validates_presence_of :email
|
||||
validates_uniqueness_of :email
|
||||
validate :username_validator
|
||||
validate :email_validator
|
||||
validate :email_validator, :if => :email_changed?
|
||||
validate :password_validator
|
||||
|
||||
before_save :cook
|
||||
|
@ -506,7 +506,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def email_validator
|
||||
if new_record? and (setting = SiteSetting.email_domains_blacklist).present?
|
||||
if (setting = SiteSetting.email_domains_blacklist).present?
|
||||
domains = setting.gsub('.', '\.')
|
||||
regexp = Regexp.new("@(#{domains})", true)
|
||||
if self.email =~ regexp
|
||||
|
|
|
@ -484,6 +484,13 @@ describe User do
|
|||
SiteSetting.stubs(:email_domains_blacklist).returns('fakemail.com')
|
||||
u.should be_valid
|
||||
end
|
||||
|
||||
it 'should be used when email is being changed' do
|
||||
SiteSetting.stubs(:email_domains_blacklist).returns('mailinator.com')
|
||||
u = Fabricate(:user, email: 'good@gmail.com')
|
||||
u.email = 'nope@mailinator.com'
|
||||
u.should_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'passwords' do
|
||||
|
|
Loading…
Reference in New Issue
Block a user