summaryrefslogtreecommitdiff
path: root/app/models/user.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-20 03:08:57 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-20 03:08:57 +0000
commit852f4a85dd199751e4652748461163de85ecda53 (patch)
treeb4160aa19c23582b5ab5ac02f9860b5498007c43 /app/models/user.rb
parent82cd20acf9f4cceecf222abe718a9e23cef55687 (diff)
downloadgitlab-ce-852f4a85dd199751e4652748461163de85ecda53.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 2c577fc9696..f3db0522edc 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -189,6 +189,7 @@ class User < ApplicationRecord
validate :owns_public_email, if: :public_email_changed?
validate :owns_commit_email, if: :commit_email_changed?
validate :signup_domain_valid?, on: :create, if: ->(user) { !user.created_by_id }
+ validate :check_email_restrictions, on: :create, if: ->(user) { !user.created_by_id }
validates :theme_id, allow_nil: true, inclusion: { in: Gitlab::Themes.valid_ids,
message: _("%{placeholder} is not a valid theme") % { placeholder: '%{value}' } }
@@ -1751,6 +1752,18 @@ class User < ApplicationRecord
end
end
+ def check_email_restrictions
+ return unless Feature.enabled?(:email_restrictions)
+ return unless Gitlab::CurrentSettings.email_restrictions_enabled?
+
+ restrictions = Gitlab::CurrentSettings.email_restrictions
+ return if restrictions.blank?
+
+ if Gitlab::UntrustedRegexp.new(restrictions).match?(email)
+ errors.add(:email, _('is not allowed for sign-up'))
+ end
+ end
+
def self.unique_internal(scope, username, email_pattern, &block)
scope.first || create_unique_internal(scope, username, email_pattern, &block)
end