コード例 #1
0
 protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
 {
     $store = null;
     $disabled = false;
     if ($code = $this->getRequest()->getParam('store')) {
         $store = Mage::getModel('core/store')->load($code);
     }
     if ($store instanceof Mage_Core_Model_Store) {
         /* @var Nosto_Tagging_Helper_Account $accountHelper */
         $accountHelper = Mage::helper('nosto_tagging/account');
         /* @var NostoAccount $nostoAccount */
         $nostoAccount = $accountHelper->find($store);
         if ($nostoAccount instanceof NostoAccountInterface) {
             foreach (NostoApiToken::getApiTokenNames() as $token) {
                 if (!$nostoAccount->getApiToken($token)) {
                     $disabled = true;
                     break;
                 }
             }
         }
     }
     if ($disabled === true) {
         /** @noinspection PhpUndefinedMethodInspection */
         $element->setDisabled('disabled');
         $metaOauth = new Nosto_Tagging_Model_Meta_Oauth();
         /** @noinspection PhpUndefinedVariableInspection */
         $metaOauth->loadData($store, $nostoAccount);
         $client = new NostoOAuthClient($metaOauth);
         $comment = sprintf('Your Nosto account is missing required tokens' . ' for updating settings to Nosto. Please click <a href="%s">' . ' here to re-connect</a> your account.', $client->getAuthorizationUrl());
         $element->setData('comment', $comment);
     }
     return parent::_getElementHtml($element);
 }
コード例 #2
0
ファイル: AccountSyncTest.php プロジェクト: nosto/php-sdk
 /**
  * Tests that existing accounts can be synced from Nosto.
  * Accounts are synced using OAuth2 Authorization Code method.
  * We are only testing that we can start and act on the steps in the OAuth request cycle.
  */
 public function testSyncingExistingAccount()
 {
     $meta = new NostoOAuthClientMetaData();
     $client = new NostoOAuthClient($meta);
     $this->specify('oauth authorize url can be created', function () use($client) {
         $this->assertEquals('http://localhost:3000?client_id=client-id&redirect_uri=http%3A%2F%2Fmy.shop.com%2Fnosto%2Foauth&response_type=code&scope=sso products&lang=en', $client->getAuthorizationUrl());
     });
     $account = NostoAccount::syncFromNosto($meta, 'test123');
     $this->specify('account was created', function () use($account, $meta) {
         $this->assertInstanceOf('NostoAccount', $account);
         $this->assertEquals('platform-00000000', $account->getName());
     });
     $this->specify('account has api token sso', function () use($account, $meta) {
         $token = $account->getApiToken('sso');
         $this->assertInstanceOf('NostoApiToken', $token);
         $this->assertEquals('sso', $token->getName());
         $this->assertNotEmpty($token->getValue());
     });
     $this->specify('account has api token products', function () use($account, $meta) {
         $token = $account->getApiToken('products');
         $this->assertInstanceOf('NostoApiToken', $token);
         $this->assertEquals('products', $token->getName());
         $this->assertNotEmpty($token->getValue());
     });
     $this->specify('account is connected to nosto', function () use($account, $meta) {
         $this->assertTrue($account->isConnectedToNosto());
     });
 }
コード例 #3
0
ファイル: Connect.php プロジェクト: Nosto/nosto-magento2
 /**
  * @return Json
  */
 public function execute()
 {
     $response = ['success' => false];
     $storeId = $this->_request->getParam('store');
     /** @var Store $store */
     $store = $this->_storeManager->getStore($storeId);
     if (!is_null($store)) {
         $metaData = $this->_oauthMetaBuilder->build($store);
         $client = new \NostoOAuthClient($metaData);
         $response['success'] = true;
         $response['redirect_url'] = $client->getAuthorizationUrl();
     }
     return $this->_result->setData($response);
 }
コード例 #4
0
 /**
  * Redirects user to the Nosto OAuth 2 authorization server to fetch missing
  * scopes (API tokens) for an account.
  */
 public function syncAccountAction()
 {
     $this->getResponse()->setHeader('Content-type', 'application/json', true);
     /** @var Nosto_Tagging_Helper_Account $accountHelper */
     $accountHelper = Mage::helper('nosto_tagging/account');
     $store = $this->getSelectedStore();
     $account = !is_null($store) ? $accountHelper->find($store) : null;
     if ($this->getRequest()->isPost() && !is_null($store) && !is_null($account)) {
         /** @var Nosto_Tagging_Model_Meta_Oauth $meta */
         $meta = new Nosto_Tagging_Model_Meta_Oauth();
         $meta->loadData($store, $account);
         $client = new NostoOAuthClient($meta);
         $responseBody = array('success' => true, 'redirect_url' => $client->getAuthorizationUrl());
     }
     if (!isset($responseBody)) {
         $responseBody = array('success' => false, 'redirect_url' => $accountHelper->getIframeUrl($store, $account, array('message_type' => NostoMessage::TYPE_ERROR, 'message_code' => NostoMessage::CODE_ACCOUNT_CONNECT)));
     }
     $this->getResponse()->setBody(json_encode($responseBody));
 }
コード例 #5
0
ファイル: NostoController.php プロジェクト: buttasg/cowgirlk
 /**
  * Redirects user to the Nosto OAuth 2 authorization server to connect and
  * existing nosto account to current scope.
  */
 public function connectAccountAction()
 {
     $this->getResponse()->setHeader('Content-type', 'application/json');
     $store = $this->getSelectedStore();
     if ($this->getRequest()->isPost() && $store !== null) {
         $client = new NostoOAuthClient(Mage::helper('nosto_tagging/oauth')->getMetaData($store));
         $responseBody = array('success' => true, 'redirect_url' => $client->getAuthorizationUrl());
     }
     if (!isset($responseBody)) {
         /** @var Nosto_Tagging_Helper_Account $accountHelper */
         $accountHelper = Mage::helper('nosto_tagging/account');
         $responseBody = array('success' => false, 'redirect_url' => $accountHelper->getIframeUrl($store, null, array('message_type' => NostoMessage::TYPE_ERROR, 'message_code' => NostoMessage::CODE_ACCOUNT_CONNECT)));
     }
     $this->getResponse()->setBody(json_encode($responseBody));
 }