Ability to skip email validation via a plugin

This commit is contained in:
Robin Ward
2016-09-07 14:05:46 -04:00
parent aeae63a56a
commit 9609a47016
4 changed files with 21 additions and 3 deletions

View File

@ -73,7 +73,7 @@ class User < ActiveRecord::Base
validates_presence_of :username
validate :username_validator, if: :username_changed?
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
validates :name, user_full_name: true, if: :name_changed?
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)
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
attr_accessor :send_welcome_message
@ -247,6 +250,10 @@ class User < ActiveRecord::Base
used_invite.try(:invited_by)
end
def should_validate_email?
return !skip_email_validation && !staged? && email_changed?
end
# Approve this user
def approve(approved_by, send_mail=true)
self.approved = true