mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
Ability to skip email validation via a plugin
This commit is contained in:
parent
aeae63a56a
commit
9609a47016
4 changed files with 21 additions and 3 deletions
|
@ -73,7 +73,7 @@ class User < ActiveRecord::Base
|
||||||
validates_presence_of :username
|
validates_presence_of :username
|
||||||
validate :username_validator, if: :username_changed?
|
validate :username_validator, if: :username_changed?
|
||||||
validates :email, presence: true, uniqueness: true
|
validates :email, presence: true, uniqueness: true
|
||||||
validates :email, email: true, if: Proc.new { |u| !u.staged && u.email_changed? }
|
validates :email, email: true, if: :should_validate_email?
|
||||||
validate :password_validator
|
validate :password_validator
|
||||||
validates :name, user_full_name: true, if: :name_changed?
|
validates :name, user_full_name: true, if: :name_changed?
|
||||||
validates :ip_address, allowed_ip_address: {on: :create, message: :signup_not_allowed}
|
validates :ip_address, allowed_ip_address: {on: :create, message: :signup_not_allowed}
|
||||||
|
@ -102,6 +102,9 @@ class User < ActiveRecord::Base
|
||||||
TopicViewItem.delete_all(user_id: self.id)
|
TopicViewItem.delete_all(user_id: self.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Skip validating email, for example from a particular auth provider plugin
|
||||||
|
attr_accessor :skip_email_validation
|
||||||
|
|
||||||
# Whether we need to be sending a system message after creation
|
# Whether we need to be sending a system message after creation
|
||||||
attr_accessor :send_welcome_message
|
attr_accessor :send_welcome_message
|
||||||
|
|
||||||
|
@ -247,6 +250,10 @@ class User < ActiveRecord::Base
|
||||||
used_invite.try(:invited_by)
|
used_invite.try(:invited_by)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def should_validate_email?
|
||||||
|
return !skip_email_validation && !staged? && email_changed?
|
||||||
|
end
|
||||||
|
|
||||||
# Approve this user
|
# Approve this user
|
||||||
def approve(approved_by, send_mail=true)
|
def approve(approved_by, send_mail=true)
|
||||||
self.approved = true
|
self.approved = true
|
||||||
|
|
|
@ -12,6 +12,8 @@ class UserAuthenticator
|
||||||
else
|
else
|
||||||
@user.password_required!
|
@user.password_required!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@user.skip_email_validation = true if @session && @session[:skip_email_validation].present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_authenticator?
|
def has_authenticator?
|
||||||
|
|
|
@ -3,7 +3,8 @@ class Auth::Result
|
||||||
:email_valid, :extra_data, :awaiting_activation,
|
:email_valid, :extra_data, :awaiting_activation,
|
||||||
:awaiting_approval, :authenticated, :authenticator_name,
|
:awaiting_approval, :authenticated, :authenticator_name,
|
||||||
:requires_invite, :not_allowed_from_ip_address,
|
:requires_invite, :not_allowed_from_ip_address,
|
||||||
:admin_not_allowed_from_ip_address, :omit_username
|
:admin_not_allowed_from_ip_address, :omit_username,
|
||||||
|
:skip_email_validation
|
||||||
|
|
||||||
attr_accessor :failed,
|
attr_accessor :failed,
|
||||||
:failed_reason
|
:failed_reason
|
||||||
|
@ -23,7 +24,8 @@ class Auth::Result
|
||||||
omit_username: omit_username,
|
omit_username: omit_username,
|
||||||
name: name,
|
name: name,
|
||||||
authenticator_name: authenticator_name,
|
authenticator_name: authenticator_name,
|
||||||
extra_data: extra_data }
|
extra_data: extra_data,
|
||||||
|
skip_email_validation: !!skip_email_validation }
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_client_hash
|
def to_client_hash
|
||||||
|
|
|
@ -477,6 +477,13 @@ describe User do
|
||||||
expect(Fabricate.build(:user, email: 'notgood@sub.domain.com')).not_to be_valid
|
expect(Fabricate.build(:user, email: 'notgood@sub.domain.com')).not_to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'skips the blacklist if skip_email_validation is set' do
|
||||||
|
SiteSetting.email_domains_blacklist = 'domain.com'
|
||||||
|
user = Fabricate.build(:user, email: 'notgood@sub.domain.com')
|
||||||
|
user.skip_email_validation = true
|
||||||
|
expect(user).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'blacklist should not reject developer emails' do
|
it 'blacklist should not reject developer emails' do
|
||||||
Rails.configuration.stubs(:developer_emails).returns('developer@discourse.org')
|
Rails.configuration.stubs(:developer_emails).returns('developer@discourse.org')
|
||||||
SiteSetting.email_domains_blacklist = 'discourse.org'
|
SiteSetting.email_domains_blacklist = 'discourse.org'
|
||||||
|
|
Loading…
Reference in a new issue