Class: Decidim::NewsletterEncryptor

Inherits:
Object
  • Object
show all
Defined in:
decidim-core/lib/decidim/newsletter_encryptor.rb

Class Method Summary collapse

Class Method Details

.crypt_dataObject



15
16
17
18
19
20
# File 'decidim-core/lib/decidim/newsletter_encryptor.rb', line 15

def self.crypt_data
  key = ActiveSupport::KeyGenerator.new("sent_at").generate_key(
    Rails.application.secrets.secret_key_base, ActiveSupport::MessageEncryptor.key_len
  )
  ActiveSupport::MessageEncryptor.new(key)
end

.sent_at_decrypted(string_encrypted) ⇒ Object

Method to decrypt sent_at newsletter.



11
12
13
# File 'decidim-core/lib/decidim/newsletter_encryptor.rb', line 11

def self.sent_at_decrypted(string_encrypted)
  crypt_data.decrypt_and_verify(string_encrypted)
end

.sent_at_encrypted(user_id, sent_at) ⇒ Object

Method to create string encrypt using sent_at time to unsubscribe’s user



6
7
8
# File 'decidim-core/lib/decidim/newsletter_encryptor.rb', line 6

def self.sent_at_encrypted(user_id, sent_at)
  crypt_data.encrypt_and_sign("#{user_id}-#{sent_at.to_i}")
end