Module: Sorcery::Model::Submodules::ActivityLogging::InstanceMethods

Defined in:
lib/sorcery/model/submodules/activity_logging.rb

Instance Method Summary collapse

Instance Method Details

#logged_in?Boolean

shows if user is logged in, but it not show if user is online - see online?

Returns:

  • (Boolean)


64
65
66
67
68
69
# File 'lib/sorcery/model/submodules/activity_logging.rb', line 64

def logged_in?
  return false if send(sorcery_config.).nil?
  return true if send(sorcery_config.).present? && send(sorcery_config.last_logout_at_attribute_name).nil?

  send(sorcery_config.) > send(sorcery_config.last_logout_at_attribute_name)
end

#logged_out?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/sorcery/model/submodules/activity_logging.rb', line 71

def logged_out?
  !logged_in?
end

#online?Boolean

online method shows if user is active (logout action makes user inactive too)

Returns:

  • (Boolean)


57
58
59
60
61
# File 'lib/sorcery/model/submodules/activity_logging.rb', line 57

def online?
  return false if send(sorcery_config.last_activity_at_attribute_name).nil?

  logged_in? && send(sorcery_config.last_activity_at_attribute_name) > sorcery_config.activity_timeout.seconds.ago
end

#set_last_activity_at(time) ⇒ Object



48
49
50
# File 'lib/sorcery/model/submodules/activity_logging.rb', line 48

def set_last_activity_at(time)
  sorcery_adapter.update_attribute(sorcery_config.last_activity_at_attribute_name, time)
end

#set_last_ip_address(ip_address) ⇒ Object



52
53
54
# File 'lib/sorcery/model/submodules/activity_logging.rb', line 52

def set_last_ip_address(ip_address)
  sorcery_adapter.update_attribute(sorcery_config., ip_address)
end

#set_last_login_at(time) ⇒ Object



40
41
42
# File 'lib/sorcery/model/submodules/activity_logging.rb', line 40

def (time)
  sorcery_adapter.update_attribute(sorcery_config., time)
end

#set_last_logout_at(time) ⇒ Object



44
45
46
# File 'lib/sorcery/model/submodules/activity_logging.rb', line 44

def set_last_logout_at(time)
  sorcery_adapter.update_attribute(sorcery_config.last_logout_at_attribute_name, time)
end