mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-04-29 23:43:55 -04:00
Better checking of blacklisted emails on create and when email is being updated
This commit is contained in:
parent
2204ded099
commit
85f8f8f2d5
2 changed files with 9 additions and 2 deletions
|
@ -27,7 +27,7 @@ class User < ActiveRecord::Base
|
||||||
validates_presence_of :email
|
validates_presence_of :email
|
||||||
validates_uniqueness_of :email
|
validates_uniqueness_of :email
|
||||||
validate :username_validator
|
validate :username_validator
|
||||||
validate :email_validator
|
validate :email_validator, :if => :email_changed?
|
||||||
validate :password_validator
|
validate :password_validator
|
||||||
|
|
||||||
before_save :cook
|
before_save :cook
|
||||||
|
@ -506,7 +506,7 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def email_validator
|
def email_validator
|
||||||
if new_record? and (setting = SiteSetting.email_domains_blacklist).present?
|
if (setting = SiteSetting.email_domains_blacklist).present?
|
||||||
domains = setting.gsub('.', '\.')
|
domains = setting.gsub('.', '\.')
|
||||||
regexp = Regexp.new("@(#{domains})", true)
|
regexp = Regexp.new("@(#{domains})", true)
|
||||||
if self.email =~ regexp
|
if self.email =~ regexp
|
||||||
|
|
|
@ -484,6 +484,13 @@ describe User do
|
||||||
SiteSetting.stubs(:email_domains_blacklist).returns('fakemail.com')
|
SiteSetting.stubs(:email_domains_blacklist).returns('fakemail.com')
|
||||||
u.should be_valid
|
u.should be_valid
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe 'passwords' do
|
describe 'passwords' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue