|
1 | 1 | class User < ApplicationRecord |
| 2 | + include ::EmailValidations |
2 | 3 | include ::UsernameValidations |
3 | 4 | include ::UserRateLimits |
4 | 5 | include ::UserMerge |
@@ -36,9 +37,6 @@ class User < ApplicationRecord |
36 | 37 | accepts_nested_attributes_for :user_websites |
37 | 38 |
|
38 | 39 | validates :login_token, uniqueness: { allow_blank: true, case_sensitive: false } |
39 | | - validate :email_domain_not_blocklisted |
40 | | - validate :not_blocklisted? |
41 | | - validate :email_not_bad_pattern |
42 | 40 |
|
43 | 41 | delegate :reputation, :reputation=, :privilege?, :privilege, to: :community_user |
44 | 42 |
|
@@ -375,54 +373,6 @@ def rtl_safe_username |
375 | 373 | "#{username}\u202D" |
376 | 374 | end |
377 | 375 |
|
378 | | - def email_domain_not_blocklisted |
379 | | - return unless File.exist?(Rails.root.join('../.qpixel-domain-blocklist.txt')) |
380 | | - return unless saved_changes.include? 'email' |
381 | | - |
382 | | - blocklist = File.read(Rails.root.join('../.qpixel-domain-blocklist.txt')).split("\n") |
383 | | - email_domain = email.split('@')[-1] |
384 | | - matched = blocklist.select { |x| email_domain == x } |
385 | | - if matched.any? |
386 | | - errors.add(:base, ApplicationRecord.useful_err_msg.sample) |
387 | | - matched_domains = matched.map { |d| "equals: #{d}" } |
388 | | - AuditLog.block_log(event_type: 'user_email_domain_blocked', |
389 | | - comment: "email: #{email}\n#{matched_domains.join("\n")}\nsource: file") |
390 | | - end |
391 | | - end |
392 | | - |
393 | | - def not_blocklisted? |
394 | | - return true unless saved_changes.include? 'email' |
395 | | - |
396 | | - email_domain = email.split('@')[-1] |
397 | | - is_mail_blocked = BlockedItem.emails.where(value: email) |
398 | | - is_mail_host_blocked = BlockedItem.email_hosts.where(value: email_domain) |
399 | | - if is_mail_blocked.any? || is_mail_host_blocked.any? |
400 | | - errors.add(:base, ApplicationRecord.useful_err_msg.sample) |
401 | | - if is_mail_blocked.any? |
402 | | - AuditLog.block_log(event_type: 'user_email_blocked', related: is_mail_blocked.first, |
403 | | - comment: "email: #{email}\nfull match to: #{is_mail_blocked.first.value}") |
404 | | - end |
405 | | - if is_mail_host_blocked.any? |
406 | | - AuditLog.block_log(event_type: 'user_email_domain_blocked', related: is_mail_host_blocked.first, |
407 | | - comment: "email: #{email}\ndomain match to: #{is_mail_host_blocked.first.value}") |
408 | | - end |
409 | | - end |
410 | | - end |
411 | | - |
412 | | - def email_not_bad_pattern |
413 | | - return unless File.exist?(Rails.root.join('../.qpixel-email-patterns.txt')) |
414 | | - return unless changes.include? 'email' |
415 | | - |
416 | | - patterns = File.read(Rails.root.join('../.qpixel-email-patterns.txt')).split("\n") |
417 | | - matched = patterns.select { |p| email.match? Regexp.new(p) } |
418 | | - if matched.any? |
419 | | - errors.add(:base, ApplicationRecord.useful_err_msg.sample) |
420 | | - matched_patterns = matched.map { |p| "matched: #{p}" } |
421 | | - AuditLog.block_log(event_type: 'user_email_pattern_match', |
422 | | - comment: "email: #{email}\n#{matched_patterns.join("\n")}") |
423 | | - end |
424 | | - end |
425 | | - |
426 | 376 | def ensure_community_user! |
427 | 377 | community_user || create_community_user(reputation: SiteSetting['NewUserInitialRep']) |
428 | 378 | end |
|
0 commit comments