Class: Masks::Rails::Recovery

Inherits:
ApplicationRecord show all
Defined in:
app/models/masks/rails/recovery.rb

Instance Method Summary collapse

Instance Method Details

#contactObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/masks/rails/recovery.rb', line 72

def contact
  return unless actor

  @contact ||=
    begin
      contact =
        if email
          actor.emails.find_by(verified: true, email:)
        elsif phone
          # TODO
        end

      contact ||= actor.emails.where(verified: true).first
      contact
    end
end

#notified?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/masks/rails/recovery.rb', line 45

def notified?
  notified_at.present?
end

#notify!Object



60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/masks/rails/recovery.rb', line 60

def notify!
  return if !valid? || notified?

  self.notified_at = Time.current
  save!

  case contact
  when Email
    ActorMailer.with(recovery: id).recover_credentials.deliver_later
  end
end

#reset_password!(password) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'app/models/masks/rails/recovery.rb', line 49

def reset_password!(password)
  return unless actor && persisted?

  actor.password = password

  return unless actor.valid?

  actor.save!
  destroy!
end

#toObject



38
39
40
41
42
43
# File 'app/models/masks/rails/recovery.rb', line 38

def to
  case contact
  when Email
    contact.email
  end
end

#to_paramObject



89
90
91
# File 'app/models/masks/rails/recovery.rb', line 89

def to_param
  token
end