Class: Morpho::Operations::User::RefreshToken

Inherits:
GenerateToken show all
Defined in:
app/concepts/morpho/operations/user/refresh_token.rb

Instance Method Summary collapse

Methods inherited from GenerateToken

#data!, #validate!

Methods inherited from Base::Find

#model_class!, #params!, #presenter_class!

Instance Method Details

#build_model!(options, data:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'app/concepts/morpho/operations/user/refresh_token.rb', line 5

def build_model!(options, data:, **)
  options['model'] = options['model.class'].find_by(refresh_token: data.fetch('refresh_token'))

  if options['model'].nil?
    raise Morpho::Exceptions::StandardError.new(
      message: I18n.t('morpho.api.messages.refresh_token.invalid'),
      status: 404
    )
  end
end

#check!(options, model:, data:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/concepts/morpho/operations/user/refresh_token.rb', line 16

def check!(options, model:, data:, **)
  unless model.active?
    raise Morpho::Exceptions::StandardError.new(
      message: I18n.t('morpho.api.messages.refresh_token.account_not_confirmed'),
      status: 403
    )
  end

  unless model.unlocked?
    raise Morpho::Exceptions::StandardError.new(
      message: I18n.t('morpho.api.messages.refresh_token.account_locked'),
      status: 423
    )
  end
end

#present!(options, model:) ⇒ Object



32
33
34
35
36
37
# File 'app/concepts/morpho/operations/user/refresh_token.rb', line 32

def present!(options, model:, **)
  model.generate_refresh_token!
  model.(options['ip_address'])
  token = Morpho::JWT::Payload.new(model)
  options['response'] = options['presenter.class'].represent(token)
end