Class: DoorMat::Process::ResetPassword

Inherits:
Object
  • Object
show all
Defined in:
lib/door_mat/process/reset_password.rb

Class Method Summary collapse

Class Method Details

.for(address, controller) ⇒ Object



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

def self.for(address, controller)
  emails = DoorMat::Email.confirmed_matching(address)
  return false if emails.blank?

  # Several DoorMat::Email could match the address
  # pick the first one for now.
  # They will all be tested at reset time to apply the reset to the proper one
  email = emails.first

  # Because email was loaded without a valid session
  # the address attribute is still encrypted.
  # Temporarily update it here with the plain text.
  # The reason it is trusted is because the hash
  # of the user input matched a previously confirmed email address
  # hash already in the system.
  email.address = address

  DoorMat::ActivityResetPassword.for(email, controller)
  true
end

.with(forgot_password) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/door_mat/process/reset_password.rb', line 26

def self.with(forgot_password)
  emails = DoorMat::Email.confirmed_matching(forgot_password.email)
  return false if emails.blank?

  activity = DoorMat::ActivityResetPassword.with(forgot_password.token, emails)
  return false if activity.blank?

  return false if forgot_password.recovery_key.blank?
  recovery_key = forgot_password.recovery_key.read

  emails.each do |email|
    if DoorMat::Process::ActorPasswordChange.after_password_reset(email.actor, forgot_password.password, recovery_key)
      DoorMat::ActivityDownloadRecoveryKey.for(email.actor)
      activity.done!
      return true
    end
  end

  activity.failed!
  return false
end