mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Compare commits
4 commits
1ccd2452a5
...
e64777413e
Author | SHA1 | Date | |
---|---|---|---|
|
e64777413e | ||
|
ef87fb8a5d | ||
|
2ac99032eb | ||
|
fa07a97815 |
3 changed files with 26 additions and 20 deletions
|
@ -1,18 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module EmailHelper
|
|
||||||
def self.included(base)
|
|
||||||
base.extend(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
def email_to_canonical_email(str)
|
|
||||||
username, domain = str.downcase.split('@', 2)
|
|
||||||
username, = username.delete('.').split('+', 2)
|
|
||||||
|
|
||||||
"#{username}@#{domain}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def email_to_canonical_email_hash(str)
|
|
||||||
Digest::SHA2.new(256).hexdigest(email_to_canonical_email(str))
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -12,7 +12,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class CanonicalEmailBlock < ApplicationRecord
|
class CanonicalEmailBlock < ApplicationRecord
|
||||||
include EmailHelper
|
include CanonicalEmail
|
||||||
include Paginable
|
include Paginable
|
||||||
|
|
||||||
belongs_to :reference_account, class_name: 'Account', optional: true
|
belongs_to :reference_account, class_name: 'Account', optional: true
|
||||||
|
@ -26,7 +26,7 @@ class CanonicalEmailBlock < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def email=(email)
|
def email=(email)
|
||||||
self.canonical_email_hash = email_to_canonical_email_hash(email)
|
self.canonical_email_hash = self.class.email_to_canonical_email_hash(email)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.block?(email)
|
def self.block?(email)
|
||||||
|
|
24
app/models/concerns/canonical_email.rb
Normal file
24
app/models/concerns/canonical_email.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module CanonicalEmail
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
class_methods do
|
||||||
|
def email_to_canonical_email_hash(value)
|
||||||
|
Digest::SHA2
|
||||||
|
.new(256)
|
||||||
|
.hexdigest(
|
||||||
|
email_to_canonical_email(value)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def email_to_canonical_email(value)
|
||||||
|
username, domain = value.downcase.split('@', 2)
|
||||||
|
username, = username.delete('.').split('+', 2)
|
||||||
|
|
||||||
|
"#{username}@#{domain}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue