2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AuthenticationEvent < ApplicationRecord
|
2021-01-03 14:25:43 +05:30
|
|
|
include UsageStatistics
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
TWO_FACTOR = 'two-factor'.freeze
|
|
|
|
TWO_FACTOR_U2F = 'two-factor-via-u2f-device'.freeze
|
|
|
|
TWO_FACTOR_WEBAUTHN = 'two-factor-via-webauthn-device'.freeze
|
|
|
|
STANDARD = 'standard'.freeze
|
|
|
|
STATIC_PROVIDERS = [TWO_FACTOR, TWO_FACTOR_U2F, TWO_FACTOR_WEBAUTHN, STANDARD].freeze
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
belongs_to :user, optional: true
|
|
|
|
|
|
|
|
validates :provider, :user_name, :result, presence: true
|
2021-01-03 14:25:43 +05:30
|
|
|
validates :ip_address, ip_address: true
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
enum result: {
|
|
|
|
failed: 0,
|
|
|
|
success: 1
|
|
|
|
}
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
scope :for_provider, ->(provider) { where(provider: provider) }
|
|
|
|
scope :ldap, -> { where('provider LIKE ?', 'ldap%')}
|
|
|
|
|
|
|
|
def self.providers
|
2021-01-29 00:20:46 +05:30
|
|
|
STATIC_PROVIDERS | Devise.omniauth_providers.map(&:to_s)
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|