Пример #1
0
 /**
  * Clean up old authorized tokens for specified consumer-user pairs
  *
  * @param \Magento\Integration\Model\Oauth\Token $exceptToken Token just created to exclude from delete
  * @throws \Magento\Framework\Model\Exception
  * @return int The number of affected rows
  */
 public function cleanOldAuthorizedTokensExcept(\Magento\Integration\Model\Oauth\Token $exceptToken)
 {
     if (!$exceptToken->getId() || !$exceptToken->getAuthorized()) {
         throw new \Magento\Framework\Model\Exception('Invalid token to except');
     }
     $adapter = $this->_getWriteAdapter();
     $where = $adapter->quoteInto('authorized = 1 AND consumer_id = ?', $exceptToken->getConsumerId(), \Zend_Db::INT_TYPE);
     $where .= $adapter->quoteInto(' AND entity_id <> ?', $exceptToken->getId(), \Zend_Db::INT_TYPE);
     if ($exceptToken->getCustomerId()) {
         $where .= $adapter->quoteInto(' AND customer_id = ?', $exceptToken->getCustomerId(), \Zend_Db::INT_TYPE);
     } elseif ($exceptToken->getAdminId()) {
         $where .= $adapter->quoteInto(' AND admin_id = ?', $exceptToken->getAdminId(), \Zend_Db::INT_TYPE);
     } else {
         throw new \Magento\Framework\Model\Exception('Invalid token to except');
     }
     return $adapter->delete($this->getMainTable(), $where);
 }
Пример #2
0
 /**
  * @param Token $token
  * @return void
  */
 protected function setUserDataViaToken(Token $token)
 {
     $this->userType = $token->getUserType();
     switch ($this->userType) {
         case UserContextInterface::USER_TYPE_INTEGRATION:
             $this->userId = $this->integrationService->findByConsumerId($token->getConsumerId())->getId();
             $this->userType = UserContextInterface::USER_TYPE_INTEGRATION;
             break;
         case UserContextInterface::USER_TYPE_ADMIN:
             $this->userId = $token->getAdminId();
             $this->userType = UserContextInterface::USER_TYPE_ADMIN;
             break;
         case UserContextInterface::USER_TYPE_CUSTOMER:
             $this->userId = $token->getCustomerId();
             $this->userType = UserContextInterface::USER_TYPE_CUSTOMER;
             break;
         default:
             /* this is an unknown user type so reset the cached user type */
             $this->userType = null;
     }
 }