class Auther::Authenticator

Manages account authentication.

Attributes

account_model[R]
account_presenter[R]
cipher[R]
logger[R]

Public Class Methods

new(secret, account_model, account_presenter, logger: LOGGER) click to toggle source

rubocop:disable Metrics/ParameterLists

# File lib/auther/authenticator.rb, line 7
def initialize secret, account_model, account_presenter, logger: LOGGER
  @cipher = Auther::Cipher.new secret
  @account_model = account_model
  @account_presenter = account_presenter
  @logger = logger
end

Public Instance Methods

authenticated?() click to toggle source

rubocop:enable Metrics/ParameterLists

# File lib/auther/authenticator.rb, line 15
def authenticated?
  account_model.valid? &&
    account_presenter.valid? &&
    authentic_name? &&
    authentic_login? &&
    authentic_password?
end

Private Instance Methods

authentic?(encrypted_value, value, error_name) click to toggle source
# File lib/auther/authenticator.rb, line 32
def authentic? encrypted_value, value, error_name
  if cipher.decrypt(encrypted_value) == value
    true
  else
    account_presenter.errors.add error_name, "is invalid"
    false
  end
rescue ActiveSupport::MessageEncryptor::InvalidMessage
  log_info %(Authentication failed! Invalid credential(s) for "#{account_model.name}" account.)
  false
end
authentic_login?() click to toggle source
# File lib/auther/authenticator.rb, line 46
def authentic_login?
  authentic? account_model.encrypted_login, account_presenter.login, "login"
end
authentic_name?(= account_presenter.name == account_model.name) click to toggle source
# File lib/auther/authenticator.rb, line 44
  def authentic_name? = account_presenter.name == account_model.name

  def authentic_login?
    authentic? account_model.encrypted_login, account_presenter.login, "login"
  end

  def authentic_password?
    authentic? account_model.encrypted_password, account_presenter.password, "password"
  end
end
authentic_password?() click to toggle source
# File lib/auther/authenticator.rb, line 50
def authentic_password?
  authentic? account_model.encrypted_password, account_presenter.password, "password"
end
log_info(message) click to toggle source
# File lib/auther/authenticator.rb, line 27
def log_info message
  id = "[#{Auther::Keymaster.namespace}]"
  logger.info [id, message].join(": ")
end