public function advancedEditAction()
 {
     $valid = true;
     $formValues = new Varien_Object(Mage::app()->getRequest()->getParams());
     /** @var $api Smartbear_Alertsite_Model_AlertsiteApi */
     $api = Mage::getModel('alertsite/alertsiteapi');
     //Let's first check to be sure that the data isn't all the same
     if ($formValues->getBasicSiteId() == $api->getDeviceId() && $formValues->getDejaUrlId() == $api->getDejaclickDeviceId() && strtolower($formValues->getLoginEmail()) == strtolower($api->getUsername()) && $formValues->getPassword() == $api->getPassword()) {
         Mage::getSingleton('adminhtml/session')->addSuccess("All settings identical");
         $this->getResponse()->setRedirect(Mage::getModel('adminhtml/url')->getUrl('*/alertsite/advance'));
     }
     //Check to make sure all form fields are set before continueing
     if (!$formValues->getBasicSiteId() || !$formValues->getDejaUrlId() || !$formValues->getLoginEmail() || !$formValues->getPassword()) {
         Mage::getSingleton('adminhtml/session')->addError('All fields are required to recover/update your account');
         $valid = false;
     }
     //We have all required fields, now let's check them all
     if ($valid) {
         //First we'll chek to be sure we can login with the username/password provided
         $valid = $api->login($formValues->getLoginEmail(), $formValues->getPassword());
         if (!$valid) {
             Mage::getSingleton('adminhtml/session')->addError('Unable to login with provided Login Email and Account Password values - please check');
         }
     }
     //Then we'll check each DejaClick and Device ID to be sure they exist and are enabled
     if ($valid) {
         $valid = $api->verifyDejaDevice($formValues->getDejaUrlId(), $formValues->getLoginEmail());
         if (!$valid) {
             Mage::getSingleton('adminhtml/session')->addError("Problem with DejaClick Device ID - " . $api->getErrorMessage());
         }
     }
     if ($valid) {
         $valid = $api->verifySiteDevice($formValues->getBasicSiteId(), $formValues->getLoginEmail());
         if (!$valid) {
             Mage::getSingleton('adminhtml/session')->addError("Problem with Site Device ID - " . $api->getErrorMessage());
         }
     }
     if (!$valid) {
         Mage::getSingleton('core/session')->setFormData($formValues);
         $this->getResponse()->setRedirect(Mage::getModel('adminhtml/url')->getUrl('*/alertsite/advance'));
     } else {
         //We've validated their account details, now we need to actually save the information to the config
         //$api->getApiReturnData()->
         $api->setCustId((string) $api->getApiReturnData()->Request->Custid);
         $api->setLogin(strtolower($formValues->getLoginEmail()));
         $api->setPass($formValues->getPassword());
         $api->setSiteUrl((string) $api->getApiReturnData()->Request->Device->Descrip);
         $api->setSiteId($formValues->getBasicSiteId());
         $api->setDejaId($formValues->getDejaUrlId());
         $api->save();
         Mage::getSingleton('adminhtml/session')->addSuccess("AlertSite configuration saved");
         $this->getResponse()->setRedirect(Mage::getModel('adminhtml/url')->getUrl('*/alertsite/advance'));
     }
 }
Example #2
0
 /**
  * Provision a new account with SmartBear's AlertSite API and return any response
  *
  * @param $parameters
  * @throws Exception - error message encountered when provisioning
  * @return bool - was the account successfully provisioned?
  */
 public function provisionAccount(Varien_Object $parameters)
 {
     //get the provisioning URL
     $url = self::ALERTSITE_PROVISION_API_URL;
     $apiFriendlyParams = array();
     $apiFriendlyParams['fname'] = urlencode($parameters->getFirstName());
     $apiFriendlyParams['lname'] = urlencode($parameters->getLastName());
     $apiFriendlyParams['phone'] = urlencode($parameters->getPhone());
     $apiFriendlyParams['company'] = urlencode($parameters->getCompanyName());
     $apiFriendlyParams['api_version'] = urlencode('1.0');
     $apiFriendlyParams['order_type'] = urlencode('magento');
     $apiFriendlyParams['response_type'] = urlencode('xml');
     $apiFriendlyParams['login_email'] = urlencode(strtolower($parameters->getLoginEmail()));
     $apiFriendlyParams['monitor_url'] = urlencode($parameters->getMonitorUrl());
     $this->setPhone($parameters->getPhone());
     $this->setCompany($apiFriendlyParams['company']);
     $this->setFName($apiFriendlyParams['fname']);
     $this->setLName($apiFriendlyParams['lname']);
     $response = $this->getCurlResponse($url, $apiFriendlyParams, 'POST', false);
     if (!$response) {
         throw new Exception("There was a problem provisioning your new account. Please try again or contact AlertSite support.");
         return false;
     }
     $status = (string) $response["status"];
     if ($status == 'failed') {
         $error = $response->Error;
         $errorMessage = (string) $error['description'];
         if ((string) $error['code'] == "0001") {
             if ($error->missing_fields) {
                 $count = count($error->missing_fields);
                 $missingFields = "";
                 if ($count > 1) {
                     foreach ($error->missing_fields as $missingField) {
                         if ((string) $missingField['name'] == 'monitor_url') {
                             $missingFields .= " - Monitor URL Required";
                         } else {
                             if ((string) $missingField['name'] == 'login_email') {
                                 $missingFields .= " - Login Email Required";
                             }
                         }
                     }
                 } else {
                     if ((string) $error->missing_fields['name'] == 'monitor_url') {
                         $missingFields .= " - Monitor URL Required";
                     } else {
                         if ((string) $error->missing_fields['name'] == 'login_email') {
                             $missingFields .= " - Login Email Required";
                         }
                     }
                 }
                 $errorMessage .= $missingFields;
             }
         }
         throw new Exception($errorMessage);
     } else {
         if ($status == 'success') {
             $this->_newAlertSiteConfig($response->AccountCreated);
             return true;
         }
     }
     return false;
 }