fix: account email validation during signup (#11307)
- Refactor email validation logic to be a service - Use the service for both email/pass signup and Google SSO - fix account email validation during signup - Use `blocked_domain` setting for both email/pass signup and Google Sign In [`BLOCKED_DOMAIN` via GlobalConfig] - add specs for `account_builder` - add specs for the new service --------- Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
36
app/services/account/sign_up_email_validation_service.rb
Normal file
36
app/services/account/sign_up_email_validation_service.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Account::SignUpEmailValidationService
|
||||
include CustomExceptions::Account
|
||||
attr_reader :email
|
||||
|
||||
def initialize(email)
|
||||
@email = email
|
||||
end
|
||||
|
||||
def perform
|
||||
address = ValidEmail2::Address.new(email)
|
||||
|
||||
raise InvalidEmail.new({ valid: false, disposable: nil }) unless address.valid?
|
||||
|
||||
raise InvalidEmail.new({ domain_blocked: true }) if domain_blocked?
|
||||
|
||||
raise InvalidEmail.new({ valid: true, disposable: true }) if address.disposable?
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def domain_blocked?
|
||||
domain = email.split('@').last&.downcase
|
||||
blocked_domains.any? { |blocked_domain| domain.match?(blocked_domain.downcase) }
|
||||
end
|
||||
|
||||
def blocked_domains
|
||||
domains = GlobalConfigService.load('BLOCKED_EMAIL_DOMAINS', '')
|
||||
return [] if domains.blank?
|
||||
|
||||
domains.split("\n").map(&:strip)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user