FEATURE: add setting auto_approve_email_domains to auto approve users (#9323)

* FEATURE: add setting `auto_approve_email_domains` to auto approve users

This commit adds a new site setting `auto_approve_email_domains` to
auto approve users based on their email address domain.

Note that if a domain already exists in `email_domains_whitelist` then
`auto_approve_email_domains` needs to be duplicated there as well,
since users won’t be able to register with email address that is
not allowed in `email_domains_whitelist`.

* Update config/locales/server.en.yml

Co-Authored-By: Robin Ward <robin.ward@gmail.com>
This commit is contained in:
Arpit Jalan
2020-03-31 23:59:15 +05:30
committed by GitHub
parent 0e3fa4072f
commit b2a0d34bb7
8 changed files with 65 additions and 5 deletions

View File

@ -22,6 +22,14 @@ class EmailValidator < ActiveModel::EachValidator
true
end
def self.can_auto_approve_user?(email)
if (setting = SiteSetting.auto_approve_email_domains).present?
return !!(EmailValidator.allowed?(email) && email_in_restriction_setting?(setting, email))
end
false
end
def self.email_in_restriction_setting?(setting, value)
domains = setting.gsub('.', '\.')
regexp = Regexp.new("@(.+\\.)?(#{domains})$", true)