/** * Clean up old authorized tokens for specified consumer-user pairs * * @param Mage_Oauth_Model_Token $exceptToken Token just created to exclude from delete * @return int The number of affected rows */ public function cleanOldAuthorizedTokensExcept(Mage_Oauth_Model_Token $exceptToken) { if (!$exceptToken->getId() || !$exceptToken->getAuthorized()) { Mage::throwException('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 { Mage::throwException('Invalid token to except'); } return $adapter->delete($this->getMainTable(), $where); }
/** * Send email notification to user about token status change * * @param Mage_Oauth_Model_Token $token Token object * @param string $newStatus Name of new token status */ protected function _sendTokenStatusChangeNotification($token, $newStatus) { if ($adminId = $token->getAdminId()) { /** @var $session Mage_Admin_Model_Session */ $session = Mage::getSingleton('admin/session'); /** @var $admin Mage_Admin_Model_User */ $admin = $session->getUser(); if ($admin->getId() == $adminId) { // skip own tokens return; } $email = $admin->getEmail(); $name = $admin->getName(' '); } else { /** @var $customer Mage_Customer_Model_Customer */ $customer = Mage::getModel('customer/customer'); $customer->load($token->getCustomerId()); $email = $customer->getEmail(); $name = $customer->getName(); } /** @var $helper Mage_Oauth_Helper_Data */ $helper = Mage::helper('oauth'); $helper->sendNotificationOnTokenStatusChange($email, $name, $token->getConsumer()->getName(), $newStatus); }
/** * Decorate user type column * * @param string $value * @param Mage_Oauth_Model_Token $row * @param Mage_Adminhtml_Block_Widget_Grid_Column $column * @param bool $isExport * @return mixed */ public function decorateUserId($value, $row, $column, $isExport) { $value = $row->getCustomerId() ? $row->getCustomerId() : $row->getAdminId(); $cell = $value; return $cell; }