Class: Admin::User

Inherits:
ApplicationRecord show all
Includes:
Koi::Model::Archivable, Koi::Model::OTP, PgSearch::Model
Defined in:
app/models/admin/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Koi::Model::OTP

#otp, #requires_otp?

Methods included from Koi::Model::Archivable

#archive, #archive!, #archived=, #archived?, #restore, #restore!

Class Method Details

.model_nameObject



8
9
10
# File 'app/models/admin/user.rb', line 8

def self.model_name
  ActiveModel::Name.new(self, nil, "AdminUser")
end

Instance Method Details

#last_active_atActiveSupport::TimeWithZone?

Describe the last time the user signed in or out. For self-reflection, excludes the current session.

Returns:

  • (ActiveSupport::TimeWithZone, nil)

    the last time the user was active



87
88
89
# File 'app/models/admin/user.rb', line 87

def last_active_at
  [, last_sign_out_at].compact.max
end

#passkey?Boolean Also known as: passkey

Returns:

  • (Boolean)


79
80
81
# File 'app/models/admin/user.rb', line 79

def passkey?
  credentials.any?
end

#password_loginObject



98
99
100
101
102
103
104
105
106
# File 'app/models/admin/user.rb', line 98

def 
  if password_digest.blank?
    :none
  elsif otp_secret.nil?
    :password_only
  else
    :mfa
  end
end

#previous_active_at(current_session = Koi::Current.session) ⇒ ActiveSupport::TimeWithZone?

Describe the last time the user signed in or out, excluding the current session (for self).

Returns:

  • (ActiveSupport::TimeWithZone, nil)

    the last time the user was active



94
95
96
# File 'app/models/admin/user.rb', line 94

def previous_active_at(current_session = Koi::Current.session)
  [last_sign_out_at, sessions.where.not(id: current_session.id).maximum(:created_at)].compact.max
end

#to_sObject



108
109
110
# File 'app/models/admin/user.rb', line 108

def to_s
  name
end