Class: DoorMat::ActivityConfirmEmail

Inherits:
Activity
  • Object
show all
Defined in:
app/models/door_mat/activity_confirm_email.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Activity

hash_token

Class Method Details

.for(email, controller) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/door_mat/activity_confirm_email.rb', line 6

def self.for(email, controller)
  return unless email.not_confirmed?

  actor = email.actor

  # Fail any existing email confirmation activities for the current email
  actor.confirm_email_activities.each do |a|
    a.failed! if email == a.email
  end
  token = SecureRandom.uuid

  activity = self.new
  activity.actor = actor
  activity.email = email
  activity.link_hash = self.hash_token(token)
  activity.started!

  activity.send_email_with(token, controller)
end

Instance Method Details

#input_valid?(token, encoded_address) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
# File 'app/models/door_mat/activity_confirm_email.rb', line 26

def input_valid?(token, encoded_address)
  DoorMat::Crypto.secure_compare(
      [DoorMat::Activity.hash_token(token.to_s), DoorMat::Email.address_hash_from_encoded_address(encoded_address)].join('_'),
      [self.link_hash, self.email.address_hash].join('_')
  ) && self.email.not_confirmed?
end

#send_email_with(token, controller) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'app/models/door_mat/activity_confirm_email.rb', line 33

def send_email_with(token, controller)
  parameters = {
      url: controller.send(:confirm_email_url, token: token, email: self.email.to_urlsafe_encoded, protocol: DoorMat::UrlProtocol.url_protocol),
      address: self.email.address
  }
  DoorMat::ActivityMailer.confirm_email(parameters).deliver_now
rescue Exception => e
  DoorMat.configuration.logger.error "ERROR: Failed to deliver confirmation email for actor #{self.actor.id} to #{self.email.address} w #{parameters[:url]} - #{e}"
  raise e
end