- 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>
37 lines
844 B
Ruby
37 lines
844 B
Ruby
# 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
|