Module: EmailValidations
- Extended by:
- ActiveSupport::Concern
- Included in:
- User
- Defined in:
- /var/apps/qpixel/app/models/concerns/email_validations.rb
Instance Method Summary collapse
- #email_domain_not_blocklisted ⇒ Object
- #email_not_bad_pattern ⇒ Object
- #email_not_blocklisted ⇒ Object
Instance Method Details
#email_domain_not_blocklisted ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File '/var/apps/qpixel/app/models/concerns/email_validations.rb', line 36 def email_domain_not_blocklisted return unless saved_changes.include?('email') email_domain = email.split('@')[-1] matched = self.class.blocklisted_email_domains.select { |x| email_domain == x } if matched.any? errors.add(:base, ApplicationRecord.useful_err_msg.sample) matched_domains = matched.map { |d| "equals: #{d}" } AuditLog.block_log(event_type: 'user_email_domain_blocked', comment: "email: #{email}\n#{matched_domains.join("\n")}\nsource: file") end end |
#email_not_bad_pattern ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File '/var/apps/qpixel/app/models/concerns/email_validations.rb', line 68 def email_not_bad_pattern return unless changes.include?('email') matched = self.class.bad_email_patterns.select { |p| email.match? Regexp.new(p) } if matched.any? errors.add(:base, ApplicationRecord.useful_err_msg.sample) matched_patterns = matched.map { |p| "matched: #{p}" } AuditLog.block_log(event_type: 'user_email_pattern_match', comment: "email: #{email}\n#{matched_patterns.join("\n")}") end end |
#email_not_blocklisted ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File '/var/apps/qpixel/app/models/concerns/email_validations.rb', line 49 def email_not_blocklisted return unless saved_changes.include?('email') email_domain = email.split('@')[-1] is_mail_blocked = BlockedItem.emails.where(value: email) is_mail_host_blocked = BlockedItem.email_hosts.where(value: email_domain) if is_mail_blocked.any? || is_mail_host_blocked.any? errors.add(:base, ApplicationRecord.useful_err_msg.sample) if is_mail_blocked.any? AuditLog.block_log(event_type: 'user_email_blocked', related: is_mail_blocked.first, comment: "email: #{email}\nfull match to: #{is_mail_blocked.first.value}") end if is_mail_host_blocked.any? AuditLog.block_log(event_type: 'user_email_domain_blocked', related: is_mail_host_blocked.first, comment: "email: #{email}\ndomain match to: #{is_mail_host_blocked.first.value}") end end end |