securityConfig = $securityConfig; $this->dateTime = $dateTime; } /** * Initialize resource model * * @return void */ protected function _construct() { $this->_init('Magento\Security\Model\ResourceModel\AdminSessionInfo'); } /** * Check if a status is logged in * * @return bool */ public function isLoggedInStatus() { $this->checkActivity(); return $this->getData('status') == self::LOGGED_IN; } /** * Check if session is timed out and set status accordingly * * @return void */ private function checkActivity() { if ($this->isSessionExpired()) { $this->setData('status', self::LOGGED_OUT); } } /** * Check whether the session is expired * * @return bool */ public function isSessionExpired() { $lifetime = $this->securityConfig->getAdminSessionLifetime(); $currentTime = $this->dateTime->gmtTimestamp(); $lastUpdatedTime = $this->getUpdatedAt(); if (!is_numeric($lastUpdatedTime)) { $lastUpdatedTime = strtotime($lastUpdatedTime); } return $lastUpdatedTime <= ($currentTime - $lifetime) ? true : false; } /** * Get formatted IP * * @return string */ public function getFormattedIp() { return $this->getIp(); } /** * Check if other sessions terminated * * @return bool */ public function isOtherSessionsTerminated() { return $this->isOtherSessionsTerminated; } /** * Setter for isOtherSessionsTerminated * * @param bool $isOtherSessionsTerminated * @return this */ public function setIsOtherSessionsTerminated($isOtherSessionsTerminated) { $this->isOtherSessionsTerminated = (bool) $isOtherSessionsTerminated; return $this; } }