Class: Account::Service::Recovery

Inherits:
Object
  • Object
show all
Defined in:
app/models/aikotoba/account/service/recovery.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account:) ⇒ Recovery

Returns a new instance of Recovery.



13
14
15
# File 'app/models/aikotoba/account/service/recovery.rb', line 13

def initialize(account:)
  @account = 
end

Class Method Details

.create_token!(account:, notify: false) ⇒ Object



5
6
7
# File 'app/models/aikotoba/account/service/recovery.rb', line 5

def self.create_token!(account:, notify: false)
  new(account: ).create_token!(notify: notify)
end

.recover!(account:, new_password:) ⇒ Object



9
10
11
# File 'app/models/aikotoba/account/service/recovery.rb', line 9

def self.recover!(account:, new_password:)
  new(account: ).recover!(new_password: new_password)
end

Instance Method Details

#create_token!(notify:) ⇒ Object



17
18
19
20
21
22
# File 'app/models/aikotoba/account/service/recovery.rb', line 17

def create_token!(notify:)
  ActiveRecord::Base.transaction do
    @account.build_recovery_token.save!
    @account.recovery_token.notify if notify
  end
end

#recover!(new_password:) ⇒ Object



24
25
26
27
28
29
# File 'app/models/aikotoba/account/service/recovery.rb', line 24

def recover!(new_password:)
  ActiveRecord::Base.transaction do
    @account.recover!(new_password: new_password)
    @account.recovery_token&.destroy!
  end
end