Class: ApiEngineBase::LoginStrategy::PlainText::Login

Inherits:
ServiceBase
  • Object
show all
Defined in:
app/services/api_engine_base/login_strategy/plain_text/login.rb

Constant Summary

Constants inherited from ServiceBase

ServiceBase::ON_ARGUMENT_VALIDATION

Instance Method Summary collapse

Methods inherited from ServiceBase

inherited, #internal_validate, #service_base_logging, #validate!

Methods included from ArgumentValidation

included

Methods included from ServiceLogging

#aletered_message, #class_name, #log, #log_error, #log_info, #log_prefix, #log_warn, #logger, #service_id

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/services/api_engine_base/login_strategy/plain_text/login.rb', line 13

def call
  if user.nil?
    log_warn("Login attempted with [#{}] => [#{}]. Resource not found")
    credential_mismatch!
  end

  if user.authenticate(password)
    user. += 1
    user.password_consecutive_fail = 0
    user.save
  else
    user.password_consecutive_fail += 1
    user.save
    log_warn("Valid #{}. Incorrect password. Consecutive Password failures: #{user.password_consecutive_fail}")
    credential_mismatch!
  end

  context.user = user

  result = ApiEngineBase::Jwt::LoginCreate.(user:)
  if result.failure?
    context.fail!(msg: "Failed to generate Authorization. Please Try again")
    return
  end

  context.token = result.token
end

#credential_mismatch!Object



41
42
43
44
# File 'app/services/api_engine_base/login_strategy/plain_text/login.rb', line 41

def credential_mismatch!
  msg = "Unauthorized Access. Incorrect Credentials"
  inline_argument_failure!(errors: {  => msg, password: msg })
end

#userObject



46
47
48
# File 'app/services/api_engine_base/login_strategy/plain_text/login.rb', line 46

def user
  @user ||= User.where( => ).first
end