/** * Authenticate user by $username and $password * * @param ModelUser $user * @return $this */ public function recordLogin(ModelUser $user) { $connection = $this->getConnection(); $data = ['logdate' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), 'lognum' => $user->getLognum() + 1]; $condition = ['user_id = ?' => (int) $user->getUserId()]; $connection->update($this->getMainTable(), $data, $condition); return $this; }
/** * @magentoDbIsolation enabled */ public function testLoginsAreLogged() { $this->_model->loadByUsername(\Magento\TestFramework\Bootstrap::ADMIN_NAME); $lognum = $this->_model->getLognum(); $beforeLogin = time(); $this->_model->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD)->reload(); $loginTime = strtotime($this->_model->getLogdate()); $this->assertTrue($beforeLogin <= $loginTime && $loginTime <= time()); $this->assertEquals(++$lognum, $this->_model->getLognum()); $beforeLogin = time(); $this->_model->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD)->reload(); $loginTime = strtotime($this->_model->getLogdate()); $this->assertTrue($beforeLogin <= $loginTime && $loginTime <= time()); $this->assertEquals(++$lognum, $this->_model->getLognum()); }
/** * Authenticate user by $username and $password * * @param ModelUser $user * @return $this */ public function recordLogin(ModelUser $user) { $adapter = $this->_getWriteAdapter(); $data = array('logdate' => $this->dateTime->now(), 'lognum' => $user->getLognum() + 1); $condition = array('user_id = ?' => (int) $user->getUserId()); $adapter->update($this->getMainTable(), $data, $condition); return $this; }