Example #1
0
 public static function isOnline()
 {
     $auth = new Qualityunit_Liveagent_Helper_Auth();
     try {
         $auth->ping();
         Mage::log('Account is online!', Zend_Log::INFO);
         return true;
     } catch (Qualityunit_Liveagent_Exception_ConnectProblem $e) {
         Mage::log('Account not online', Zend_Log::INFO);
         return false;
     }
 }
 private function doPostAction()
 {
     $post = $this->getRequest()->getPost();
     if (!array_key_exists('action', $post)) {
         $this->doAfterPost();
         return;
     }
     if ($post['action'] == "r") {
         try {
             $this->validateSignupMail($post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME]);
             $this->registerAccountAction($post[Qualityunit_Liveagent_Block_Signup::FULL_NAME_FIELD], $post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME], $post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME], substr(md5(microtime()), 0, 8), '');
         } catch (Qualityunit_Liveagent_Exception_SignupFailed $e) {
             $this->signupFailed($e);
             return;
         }
         $this->doAfterPost();
         return;
     }
     if ($post['action'] == Qualityunit_Liveagent_Block_Account::SAVE_ACCOUNT_SETTINGS_ACTION_FLAG) {
         if (!$this->checkAccountSettings($post)) {
             $this->doAfterPost($this->getAccountSettingsPost($post));
             return;
         }
         $auth = new Qualityunit_Liveagent_Helper_Auth();
         try {
             $auth->ping($post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME]);
         } catch (Qualityunit_Liveagent_Exception_ConnectProblem $e) {
             Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Unable to connect to LiveAgent at') . ' ' . $post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME] . '. ' . $this->getAccountSettingsChangeRevertLink());
             $this->doAfterPost($this->getAccountSettingsPost($post));
             return;
         }
         try {
             $auth->LoginAndGetLoginData($post[Qualityunit_Liveagent_Helper_Settings::LA_URL_SETTING_NAME], $post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_EMAIL_SETTING_NAME], $post[Qualityunit_Liveagent_Helper_Settings::LA_OWNER_PASSWORD_SETTING_NAME]);
         } catch (Qualityunit_Liveagent_Exception_ConnectProblem $e) {
             Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Unable to login to LiveAgent with given credentails. Please check your username and password.') . ' ' . $this->getAccountSettingsChangeRevertLink());
             $this->doAfterPost($this->getAccountSettingsPost($post));
             return;
         }
         $this->saveAccountSettings($post);
         if (!$this->isSetStatus()) {
             $this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::ACCOUNT_STATUS, Qualityunit_Liveagent_Helper_Base::ACCOUNT_STATUS_SET);
         }
         Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Account settings were saved successfully'));
     }
     if ($post['action'] == Qualityunit_Liveagent_Block_Buttoncode::SAVE_BUTTON_CODE_ACTION_FLAG) {
         $this->settings->setOption(Qualityunit_Liveagent_Helper_Settings::BUTTON_CODE, html_entity_decode($post[Qualityunit_Liveagent_Helper_Settings::BUTTON_CODE]));
         Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Button code was saved successfully'));
     }
     $this->doAfterPost();
 }
 public function login()
 {
     $auth = new Qualityunit_Liveagent_Helper_Auth();
     $loginData = $auth->LoginAndGetLoginData();
     try {
         $sessionId = $loginData->getValue('session');
         $this->setOption(Qualityunit_Liveagent_Helper_Settings::OWNER_SESSIONID, $sessionId);
     } catch (La_Data_RecordSetNoRowException $e) {
         throw new Qualityunit_Liveagent_Exception_ConnectProblem();
     }
     try {
         $token = $loginData->getValue('authtoken');
         $sessionId = $token;
         $this->setOption(Qualityunit_Liveagent_Helper_Settings::OWNER_AUTHTOKEN, $token);
     } catch (La_Data_RecordSetNoRowException $e) {
         // we are communicating with older LA that does not send auth token
         $this->setOption(Qualityunit_Liveagent_Helper_Settings::OWNER_AUTHTOKEN, '');
     }
     return $sessionId;
 }