Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Oauth_Adminhtml_Oauth_Admin_TokenController
  • Mage_Oauth_Adminhtml_Oauth_AuthorizeController
  • Mage_Oauth_Adminhtml_Oauth_AuthorizedTokensController
  • Mage_Oauth_Adminhtml_Oauth_ConsumerController
  • Mage_Oauth_AuthorizeController
  • Mage_Oauth_Block_Adminhtml_Oauth_Admin_Token
  • Mage_Oauth_Block_Adminhtml_Oauth_Admin_Token_Grid
  • Mage_Oauth_Block_Adminhtml_Oauth_Authorize
  • Mage_Oauth_Block_Adminhtml_Oauth_Authorize_Button
  • Mage_Oauth_Block_Adminhtml_Oauth_AuthorizedTokens
  • Mage_Oauth_Block_Adminhtml_Oauth_AuthorizedTokens_Grid
  • Mage_Oauth_Block_Adminhtml_Oauth_Consumer
  • Mage_Oauth_Block_Adminhtml_Oauth_Consumer_Edit
  • Mage_Oauth_Block_Adminhtml_Oauth_Consumer_Edit_Form
  • Mage_Oauth_Block_Adminhtml_Oauth_Consumer_Grid
  • Mage_Oauth_Block_Authorize
  • Mage_Oauth_Block_Authorize_Abstract
  • Mage_Oauth_Block_Authorize_Button
  • Mage_Oauth_Block_Authorize_ButtonBaseAbstract
  • Mage_Oauth_Block_AuthorizeBaseAbstract
  • Mage_Oauth_Block_Customer_Token_List
  • Mage_Oauth_Customer_TokenController
  • Mage_Oauth_Exception
  • Mage_Oauth_Helper_Data
  • Mage_Oauth_InitiateController
  • Mage_Oauth_Model_Consumer
  • Mage_Oauth_Model_Consumer_Validator_KeyLength
  • Mage_Oauth_Model_Nonce
  • Mage_Oauth_Model_Observer
  • Mage_Oauth_Model_Resource_Consumer
  • Mage_Oauth_Model_Resource_Consumer_Collection
  • Mage_Oauth_Model_Resource_Nonce
  • Mage_Oauth_Model_Resource_Nonce_Collection
  • Mage_Oauth_Model_Resource_Setup
  • Mage_Oauth_Model_Resource_Token
  • Mage_Oauth_Model_Resource_Token_Collection
  • Mage_Oauth_Model_Server
  • Mage_Oauth_Model_Token
  • Mage_Oauth_TokenController
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Oauth
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * Manage consumers controller
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_Oauth
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Oauth_Adminhtml_Oauth_ConsumerController extends Mage_Adminhtml_Controller_Action
 35: {
 36:     /**
 37:      * Unset unused data from request
 38:      * Skip getting "key" and "secret" because its generated from server side only
 39:      *
 40:      * @param array $data
 41:      * @return array
 42:      */
 43:     protected function _filter(array $data)
 44:     {
 45:         foreach (array('id', 'back', 'form_key', 'key', 'secret') as $field) {
 46:             if (isset($data[$field])) {
 47:                 unset($data[$field]);
 48:             }
 49:         }
 50:         return $data;
 51:     }
 52: 
 53:     /**
 54:      * Init titles
 55:      *
 56:      * @return Mage_Oauth_Adminhtml_Oauth_ConsumerController
 57:      */
 58:     public function preDispatch()
 59:     {
 60:         $this->_title($this->__('System'))
 61:             ->_title($this->__('OAuth'))
 62:             ->_title($this->__('Consumers'));
 63:         parent::preDispatch();
 64:         return $this;
 65:     }
 66: 
 67:     /**
 68:      * Render grid page
 69:      */
 70:     public function indexAction()
 71:     {
 72:         $this->loadLayout();
 73:         $this->renderLayout();
 74:     }
 75: 
 76:     /**
 77:      * Render grid AJAX request
 78:      */
 79:     public function gridAction()
 80:     {
 81:         $this->loadLayout();
 82:         $this->renderLayout();
 83:     }
 84: 
 85:     /**
 86:      * Create page action
 87:      */
 88:     public function newAction()
 89:     {
 90:         /** @var $model Mage_Oauth_Model_Consumer */
 91:         $model = Mage::getModel('oauth/consumer');
 92: 
 93:         $formData = $this->_getFormData();
 94:         if ($formData) {
 95:             $this->_setFormData($formData);
 96:             $model->addData($formData);
 97:         } else {
 98:             /** @var $helper Mage_Oauth_Helper_Data */
 99:             $helper = Mage::helper('oauth');
100:             $model->setKey($helper->generateConsumerKey());
101:             $model->setSecret($helper->generateConsumerSecret());
102:             $this->_setFormData($model->getData());
103:         }
104: 
105:         Mage::register('current_consumer', $model);
106: 
107:         $this->loadLayout();
108:         $this->renderLayout();
109:     }
110: 
111:     /**
112:      * Edit page action
113:      */
114:     public function editAction()
115:     {
116:         $id = (int) $this->getRequest()->getParam('id');
117: 
118:         if (!$id) {
119:             $this->_getSession()->addError(Mage::helper('oauth')->__('Invalid ID parameter.'));
120:             $this->_redirect('*/*/index');
121:             return;
122:         }
123: 
124:         /** @var $model Mage_Oauth_Model_Consumer */
125:         $model = Mage::getModel('oauth/consumer');
126:         $model->load($id);
127: 
128:         if (!$model->getId()) {
129:             $this->_getSession()->addError(Mage::helper('oauth')->__('Entry with ID #%s not found.', $id));
130:             $this->_redirect('*/*/index');
131:             return;
132:         }
133: 
134:         $model->addData($this->_filter($this->getRequest()->getParams()));
135:         Mage::register('current_consumer', $model);
136: 
137:         $this->loadLayout();
138:         $this->renderLayout();
139:     }
140: 
141:     /**
142:      * Render edit page
143:      */
144:     public function saveAction()
145:     {
146:         $id = $this->getRequest()->getParam('id');
147:         if (!$this->_validateFormKey()) {
148:             if ($id) {
149:                 $this->_redirect('*/*/edit', array('id' => $id));
150:             } else {
151:                 $this->_redirect('*/*/new', array('id' => $id));
152:             }
153:             return;
154:         }
155: 
156:         $data = $this->_filter($this->getRequest()->getParams());
157: 
158:         /** @var $model Mage_Oauth_Model_Consumer */
159:         $model = Mage::getModel('oauth/consumer');
160: 
161:         if ($id) {
162:             if (!(int) $id) {
163:                 $this->_getSession()->addError(
164:                     $this->__('Invalid ID parameter.'));
165:                 $this->_redirect('*/*/index');
166:                 return;
167:             }
168:             $model->load($id);
169: 
170:             if (!$model->getId()) {
171:                 $this->_getSession()->addError(
172:                     $this->__('Entry with ID #%s not found.', $id));
173:                 $this->_redirect('*/*/index');
174:                 return;
175:             }
176:         } else {
177:             $dataForm = $this->_getFormData();
178:             if ($dataForm) {
179:                 $data['key']    = $dataForm['key'];
180:                 $data['secret'] = $dataForm['secret'];
181:             } else {
182:                 // If an admin was started create a new consumer and at this moment he has been edited an existing
183:                 // consumer, we save the new consumer with a new key-secret pair
184:                 /** @var $helper Mage_Oauth_Helper_Data */
185:                 $helper = Mage::helper('oauth');
186: 
187:                 $data['key']    = $helper->generateConsumerKey();
188:                 $data['secret'] = $helper->generateConsumerSecret();
189:             }
190:         }
191: 
192:         try {
193:             $model->addData($data);
194:             $model->save();
195:             $this->_getSession()->addSuccess($this->__('The consumer has been saved.'));
196:             $this->_setFormData(null);
197:         } catch (Mage_Core_Exception $e) {
198:             $this->_setFormData($data);
199:             $this->_getSession()->addError(Mage::helper('core')->escapeHtml($e->getMessage()));
200:             $this->getRequest()->setParam('back', 'edit');
201:         } catch (Exception $e) {
202:             $this->_setFormData(null);
203:             Mage::logException($e);
204:             $this->_getSession()->addError($this->__('An error occurred on saving consumer data.'));
205:         }
206: 
207:         if ($this->getRequest()->getParam('back')) {
208:             if ($id || $model->getId()) {
209:                 $this->_redirect('*/*/edit', array('id' => $model->getId()));
210:             } else {
211:                 $this->_redirect('*/*/new');
212:             }
213:         } else {
214:             $this->_redirect('*/*/index');
215:         }
216:     }
217: 
218:     /**
219:      * Check admin permissions for this controller
220:      *
221:      * @return boolean
222:      */
223:     protected function _isAllowed()
224:     {
225:         $action = $this->getRequest()->getActionName();
226:         if ('index' == $action) {
227:             $action = null;
228:         } else {
229:             if ('new' == $action || 'save' == $action) {
230:                 $action = 'edit';
231:             }
232:             $action = '/' . $action;
233:         }
234:         /** @var $session Mage_Admin_Model_Session */
235:         $session = Mage::getSingleton('admin/session');
236:         return $session->isAllowed('system/oauth/consumer' . $action);
237:     }
238: 
239:     /**
240:      * Get form data
241:      *
242:      * @return array
243:      */
244:     protected function _getFormData()
245:     {
246:         return $this->_getSession()->getData('consumer_data', true);
247:     }
248: 
249:     /**
250:      * Set form data
251:      *
252:      * @param $data
253:      * @return Mage_Oauth_Adminhtml_Oauth_ConsumerController
254:      */
255:     protected function _setFormData($data)
256:     {
257:         $this->_getSession()->setData('consumer_data', $data);
258:         return $this;
259:     }
260: 
261:     /**
262:      * Delete consumer action
263:      */
264:     public function deleteAction()
265:     {
266:         $consumerId = (int) $this->getRequest()->getParam('id');
267:         if ($consumerId) {
268:             try {
269:                 /** @var $consumer Mage_Oauth_Model_Consumer */
270:                 $consumer = Mage::getModel('oauth/consumer')->load($consumerId);
271:                 if (!$consumer->getId()) {
272:                     Mage::throwException(Mage::helper('oauth')->__('Unable to find a consumer.'));
273:                 }
274: 
275:                 $consumer->delete();
276: 
277:                 $this->_getSession()->addSuccess(Mage::helper('oauth')->__('The consumer has been deleted.'));
278:             } catch (Mage_Core_Exception $e) {
279:                 $this->_getSession()->addError($e->getMessage());
280:             } catch (Exception $e) {
281:                 $this->_getSession()->addException(
282:                     $e, Mage::helper('oauth')->__('An error occurred while deleting the consumer.')
283:                 );
284:             }
285:         }
286:         $this->_redirect('*/*/index');
287:     }
288: }
289: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0