Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function createAdminAccessToken($username, $password)
 {
     $this->validatorHelper->validate($username, $password);
     $this->userModel->login($username, $password);
     if (!$this->userModel->getId()) {
         /*
          * This message is same as one thrown in \Magento\Backend\Model\Auth to keep the behavior consistent.
          * Constant cannot be created in Auth Model since it uses legacy translation that doesn't support it.
          * Need to make sure that this is refactored once exception handling is updated in Auth Model.
          */
         throw new AuthenticationException(__('You did not sign in correctly or your account is temporarily disabled.'));
     }
     return $this->tokenModelFactory->create()->createAdminToken($this->userModel->getId())->getToken();
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function createAdminAccessToken($username, $password)
 {
     $this->validatorHelper->validateCredentials($username, $password);
     try {
         $this->userModel->login($username, $password);
         if (!$this->userModel->getId()) {
             /*
              * This message is same as one thrown in \Magento\Backend\Model\Auth to keep the behavior consistent.
              * Constant cannot be created in Auth Model since it uses legacy translation that doesn't support it.
              * Need to make sure that this is refactored once exception handling is updated in Auth Model.
              */
             throw new AuthenticationException('Please correct the user name or password.');
         }
     } catch (\Magento\Backend\Model\Auth\Exception $e) {
         throw new AuthenticationException($e->getMessage(), [], $e);
     } catch (\Magento\Framework\Model\Exception $e) {
         throw new LocalizedException($e->getMessage(), [], $e);
     }
     return $this->tokenModelFactory->create()->createAdminToken($this->userModel->getId())->getToken();
 }
Exemplo n.º 3
0
 /**
  * @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());
 }