mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 11:37:58 +00:00
feat: add domain blocklist feature (#10016)
Co-authored-by: Pranav <pranav@chatwoot.com>
This commit is contained in:
@@ -32,6 +32,8 @@ class AccountBuilder
|
|||||||
end
|
end
|
||||||
|
|
||||||
def validate_email
|
def validate_email
|
||||||
|
raise InvalidEmail.new({ domain_blocked: domain_blocked }) if domain_blocked?
|
||||||
|
|
||||||
address = ValidEmail2::Address.new(@email)
|
address = ValidEmail2::Address.new(@email)
|
||||||
if address.valid? && !address.disposable?
|
if address.valid? && !address.disposable?
|
||||||
true
|
true
|
||||||
@@ -79,4 +81,21 @@ class AccountBuilder
|
|||||||
@user.confirm if @confirmed
|
@user.confirm if @confirmed
|
||||||
@user.save!
|
@user.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def domain_blocked?
|
||||||
|
domain = @email.split('@').last
|
||||||
|
|
||||||
|
blocked_domains.each do |blocked_domain|
|
||||||
|
return true if domain.match?(blocked_domain)
|
||||||
|
end
|
||||||
|
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def blocked_domains
|
||||||
|
domains = GlobalConfigService.load('BLOCKED_EMAIL_DOMAINS', '')
|
||||||
|
domains.split("\n").map(&:strip) if domains.present?
|
||||||
|
|
||||||
|
[]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -168,6 +168,11 @@
|
|||||||
display_title: 'Dashboard Scripts'
|
display_title: 'Dashboard Scripts'
|
||||||
description: 'Scripts are loaded as the last item in the <body> tag'
|
description: 'Scripts are loaded as the last item in the <body> tag'
|
||||||
type: code
|
type: code
|
||||||
|
- name: BLOCKED_EMAIL_DOMAINS
|
||||||
|
value:
|
||||||
|
display_title: 'Blocked Email Domains'
|
||||||
|
description: 'Add a domain per line to block them from signing up, accepts Regex'
|
||||||
|
type: code
|
||||||
# ------- End of Chatwoot Internal Config for Cloud ----#
|
# ------- End of Chatwoot Internal Config for Cloud ----#
|
||||||
|
|
||||||
# ------- Chatwoot Internal Config for Self Hosted ----#
|
# ------- Chatwoot Internal Config for Self Hosted ----#
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ en:
|
|||||||
invalid: Invalid events
|
invalid: Invalid events
|
||||||
signup:
|
signup:
|
||||||
disposable_email: We do not allow disposable emails
|
disposable_email: We do not allow disposable emails
|
||||||
|
blocked_domain: This domain is not allowed. If you believe this is a mistake, please contact support.
|
||||||
invalid_email: You have entered an invalid email
|
invalid_email: You have entered an invalid email
|
||||||
email_already_exists: "You have already signed up for an account with %{email}"
|
email_already_exists: "You have already signed up for an account with %{email}"
|
||||||
invalid_params: 'Invalid, please check the signup paramters and try again'
|
invalid_params: 'Invalid, please check the signup paramters and try again'
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ module Enterprise::SuperAdmin::AppConfigsController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def internal_config_options
|
def internal_config_options
|
||||||
%w[CHATWOOT_INBOX_TOKEN CHATWOOT_INBOX_HMAC_KEY ANALYTICS_TOKEN CLEARBIT_API_KEY DASHBOARD_SCRIPTS]
|
%w[CHATWOOT_INBOX_TOKEN CHATWOOT_INBOX_HMAC_KEY ANALYTICS_TOKEN CLEARBIT_API_KEY DASHBOARD_SCRIPTS BLOCKED_EMAIL_DOMAINS]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
module CustomExceptions::Account
|
module CustomExceptions::Account
|
||||||
class InvalidEmail < CustomExceptions::Base
|
class InvalidEmail < CustomExceptions::Base
|
||||||
def message
|
def message
|
||||||
if @data[:disposable]
|
if @data[:domain_blocked]
|
||||||
|
I18n.t 'errors.signup.blocked_domain'
|
||||||
|
elsif @data[:disposable]
|
||||||
I18n.t 'errors.signup.disposable_email'
|
I18n.t 'errors.signup.disposable_email'
|
||||||
elsif !@data[:valid]
|
elsif !@data[:valid]
|
||||||
I18n.t 'errors.signup.invalid_email'
|
I18n.t 'errors.signup.invalid_email'
|
||||||
|
|||||||
Reference in New Issue
Block a user