/** * Authenticate Action * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $this->_eventManager->dispatch('mperf_authenticate'); $resultRedirect = $this->resultRedirectFactory->create(); /* Get my own infos */ $result = $this->_restHelper->get('me'); if ($result['info']['http_code'] < 200 || $result['info']['http_code'] > 299) { return $this->redirectToError($resultRedirect, 'API ' . __('Call') . ' : \'GET\' ' . __('on') . ' \'/me\' ' . __('failed. Please check your XKey')); } $result = $result['result']; /* Get more infos about me */ $contactResult = $this->_restHelper->get('contacts/' . $result['id']); if ($contactResult['info']['http_code'] < 200 || $contactResult['info']['http_code'] > 299) { return $this->redirectToError($resultRedirect, 'API ' . __('Call') . ' : \'GET\' ' . __('on') . ' \'/contacts/' . $result['id'] . '\' ' . __('failed. Please check your XKey')); } $contactResult = $contactResult['result']; $this->saveContactInfos($result, $contactResult); /* Final step: Redirect to param page */ if ($this->_config->isReady()) { $this->messageManager->addSuccess(__('You succesfully linked your XKey to Magento2')); /* Since we just auth, we now need to generate the mailperformance pre-stored bindings */ return $this->_redirect('*/Check/Reload', ['path' => $this->getRequest()->getParam('path')]); } return $this->redirectToError($resultRedirect, __('Unknown error, please try again later')); }
/** * If plugin is locked, will return this page * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { $this->_eventManager->dispatch('mperf_request', ['from' => 'Check']); if ($this->_config->isReady()) { $resultRedirect = $this->resultRedirectFactory->create(); return $this->_redirect('*/' . $this->getRequest()->getParam('path')); } else { $this->messageManager->addWarning(__('Your MailPerformance XKey hasn\'t been validated yet or is not valid anymore')); $resultPageFactory = $this->_objectManager->create('Magento\\Framework\\View\\Result\\PageFactory'); $resultPage = $resultPageFactory->create(); return $resultPage; } }