_pageHeaderTemplates['headerView'] = ''; $contactUs = 'contact us'; if (null != ($contactUsLink = $this->getConfig('sts')->contactUsLink)) { $contactUs = 'contact us'; } $this->_messageCodeGen = str_replace('%contactUs%', $contactUs, self::MESSAGE_CODE_GEN_DENNY); $this->_stsUrlDomain = $this->getConfig('sts')->stsUrlDomain; $this->_stsUrlDomain = rtrim($this->_stsUrlDomain, '/ '); return $this; } public function exec() { if ('n' == $this->_getDataObj()->getStsLoginEnabled()) { $this->redirect(BASE_URL_LANGUAGE . '/admin'); } $this->_doc->setHeader(''); $this->_doc->addItem(array('tpl' => $this->getTemplate('redirect-to-sts-item.tpl'))); parent::exec(); return $this; } public function getStsUrlDomain() { if (null === $this->_stsUrlDomain) { throw new Qs_Exception('Online Support System Url is not defined'); } return $this->_stsUrlDomain; } public function getLoginForm() { $form = $this->_getFormInstance('login'); return $form; } protected function _doView() { if (null == ($this->_code = $this->_getDataObj()->getStsAuthCode())) { $form = $this->getLoginForm(); $this->_addFormItem($form); } else { if (self::CODE_GEN_OK == ($resultCodeGen = $this->_doStsToGenCode())) { $this->_redirectToSts(); } elseif ($resultCodeGen == self::CODE_GEN_EMPTY) { $form = $this->getLoginForm(); $this->_addFormItem($form); } elseif ($resultCodeGen == self::CODE_GEN_DENNY) { $this->_doc->displayMessage($this->_messageCodeGen); } elseif (!$resultCodeGen) { $this->_doc->displayMessage(self::FAILED_STS_RESPONSE); } } return $this; } protected function _doLogin() { $form = $this->getLoginForm(); if ($form->validate()) { if (self::CODE_GEN_OK == ($resultCodeGen = $this->_doStsToGenCode($form->getValue('sts_login'), $form->getValue('sts_password')))) { $form->clearDecorators(); $this->_redirectToSts(); } elseif ($resultCodeGen == self::CODE_GEN_EMPTY) { $decorators = $form->getDecorators(); $form->addDecorator('Errors', array('placement' => 'prepend')); $form->addError('Invalid Username or Password'); } elseif ($resultCodeGen == self::CODE_GEN_DENNY) { $this->_doc->displayMessage($this->_messageCodeGen); return $this; } elseif (!$resultCodeGen) { $this->_doc->displayMessage(self::FAILED_STS_RESPONSE); } } $this->_addFormItem($form); return $this; } protected function _doStsToGenCode($login = null, $passwd = null) { $dataSend = array('action' => 'getRemoteAuthCode'); if (!empty($this->_code)) { $dataSend['code'] = $this->_code; } elseif (!empty($login) && !empty($passwd)) { $dataSend['login'] = $login; $dataSend['password'] = md5($passwd); } $config = array( 'keepalive' => true, 'strictredirects' => true ); $client = new Zend_Http_Client($this->getStsUrlDomain() . '/__generate-auth-code', $config); $client->setMethod('POST'); $client->setCookieJar(false); $client->setParameterPost($dataSend); $response = $client->request('POST'); if (200 != $response->getStatus()) { return false; } $headers = Zend_Http_Response::extractHeaders($response); if (isset($headers['transfer-encoding']) && $headers['transfer-encoding'] == 'gzip') { $body = Zend_Http_Response::extractBody($response); $dataCode = Zend_Http_Response::decodeGzip($body); } else { $dataCode = $response->getBody(); } preg_match('/\(code\[\/([a-z0-9]{32}|empty|denny)\/\]/', $dataCode, $matches); if (!empty($matches[1]) && $matches[1] != 'denny' && $matches[1] != 'empty') { $this->_getDataObj()->updateStsLoginCode($matches[1]); $this->_code = $matches[1]; return self::CODE_GEN_OK; } elseif ($matches[1] == 'empty') { return self::CODE_GEN_EMPTY; } elseif ($matches[1] == 'denny') { return self::CODE_GEN_DENNY; } return false; } protected function _redirectToSts() { $this->_doc->addItem(array('tpl' => $this->getTemplate('loader.tpl'))); $options = array( 'action' => $this->_stsUrlDomain . '/login', 'method' => 'POST', 'code' => $this->_code, ); $redirectForm = $this->_getFormInstance('redirect', $options); $redirectForm->setAttrib('id', $redirectForm->getAttrib('id') . '-redirect'); $this->_addFormItem($redirectForm); return $this; } }