/** * Check whether the session is expired * * @return bool */ public function isSessionExpired() { $lifetime = $this->securityConfig->getAdminSessionLifetime(); $currentTime = $this->securityConfig->getCurrentTimestamp(); $lastUpdatedTime = $this->getUpdatedAt(); if (!is_numeric($lastUpdatedTime)) { $lastUpdatedTime = strtotime($lastUpdatedTime); } return $lastUpdatedTime <= $currentTime - $lifetime ? true : false; }
/** * Logout another user sessions * * @return $this */ public function logoutOtherUserSessions() { $collection = $this->createAdminSessionInfoCollection()->filterByUser($this->authSession->getUser()->getId(), \Magento\Security\Model\AdminSessionInfo::LOGGED_IN, $this->authSession->getSessionId())->filterExpiredSessions($this->securityConfig->getAdminSessionLifetime())->loadData(); $collection->setDataToAll('status', \Magento\Security\Model\AdminSessionInfo::LOGGED_OUT_MANUALLY)->save(); return $this; }
/** * Test get admin session lifetime * @return void */ public function testGetAdminSessionLifetime() { $lifetime = 10; $this->scopeConfigMock->expects($this->once())->method('getValue')->with(\Magento\Backend\Model\Auth\Session::XML_PATH_SESSION_LIFETIME)->will($this->returnValue($lifetime)); $this->assertEquals($lifetime, $this->helper->getAdminSessionLifetime()); }