Class: Morpho::Operations::User::SignIn
Instance Method Summary
collapse
#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/sign_in.rb', line 5
def build_model!(options, data:, **)
options['model'] = options['model.class'].find_by(email: data.fetch('email'))
if options['model'].nil?
raise Morpho::Exceptions::StandardError.new(
message: I18n.t('morpho.api.messages.sign_in.email_not_exists'),
status: 404
)
end
end
|
#check!(options, model:, data:) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/concepts/morpho/operations/user/sign_in.rb', line 16
def check!(options, model:, data:, **)
unless model.active?
raise Morpho::Exceptions::StandardError.new(
message: I18n.t('morpho.api.messages.sign_in.account_not_confirmed'),
status: 403
)
end
unless model.unlocked?
raise Morpho::Exceptions::StandardError.new(
message: I18n.t('morpho.api.messages.sign_in.account_locked'),
status: 423
)
end
unless model.valid_password?(data.fetch('password'))
model.register_failed_login!
raise Morpho::Exceptions::StandardError.new(
message: I18n.t('morpho.api.messages.sign_in.bad_credentials'),
status: 401
)
end
end
|
#present!(options, model:) ⇒ Object
40
41
42
43
44
45
|
# File 'app/concepts/morpho/operations/user/sign_in.rb', line 40
def present!(options, model:, **)
model.generate_refresh_token!
model.register_last_login_activity!(options['ip_address'])
token = Morpho::JWT::Payload.new(model)
options['response'] = options['presenter.class'].represent(token)
end
|