login_activity.rb 885 B

123456789101112131415161718192021222324252627282930313233343536
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: login_activities
  5. #
  6. # id :bigint(8) not null, primary key
  7. # user_id :bigint(8) not null
  8. # authentication_method :string
  9. # provider :string
  10. # success :boolean
  11. # failure_reason :string
  12. # ip :inet
  13. # user_agent :string
  14. # created_at :datetime
  15. #
  16. class LoginActivity < ApplicationRecord
  17. enum authentication_method: { password: 'password', otp: 'otp', webauthn: 'webauthn', sign_in_token: 'sign_in_token', omniauth: 'omniauth' }
  18. belongs_to :user
  19. validates :authentication_method, inclusion: { in: authentication_methods.keys }
  20. def detection
  21. @detection ||= Browser.new(user_agent)
  22. end
  23. def browser
  24. detection.id
  25. end
  26. def platform
  27. detection.platform.id
  28. end
  29. end