The code powering m.abunchtell.com https://m.abunchtell.com
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

37 righe
806 B

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: email_domain_blocks
  5. #
  6. # id :bigint not null, primary key
  7. # domain :string default(""), not null
  8. # created_at :datetime not null
  9. # updated_at :datetime not null
  10. #
  11. class EmailDomainBlock < ApplicationRecord
  12. before_validation :normalize_domain
  13. validates :domain, presence: true, uniqueness: true
  14. def self.block?(email)
  15. _, domain = email.split('@', 2)
  16. return true if domain.nil?
  17. begin
  18. domain = TagManager.instance.normalize_domain(domain)
  19. rescue Addressable::URI::InvalidURIError
  20. return true
  21. end
  22. where(domain: domain).exists?
  23. end
  24. private
  25. def normalize_domain
  26. self.domain = TagManager.instance.normalize_domain(domain)
  27. end
  28. end