public function loginAction() { $this->shopUrl = urlencode(Mage::app()->getStore()->getBaseUrl()); $this->shopName = urlencode(Mage::app()->getStore()->getName()); $params = $this->getRequest()->getParams(); $config = new Clearcode_Addshoppers_Helper_Config($params['store']); if ($config->getActive() != 1) { $config->setSocialEnabled(1); $params['configuration']['social'] = 1; $config->setOpenGraphEnabled(1); $params['configuration']['opengraph'] = 1; $config->setSchemaEnabled(1); $params['configuration']['use_schema'] = 1; } $data = "login="******"&password="******"&url=" . $this->shopUrl . "&category=Other" . "&phone=" . urlencode($config->getPhone()) . "&platform=" . $this->platform . "&site_name=" . $this->shopName; $return = $this->sendRequestWithBasicAuth($this->api_url . '/login', $data); if ($return['result'] == 17) { $message = Clearcode_Addshoppers_Block_Adminform::DOMAIN_BANNED; } elseif ($return['result'] == 11) { $message = Clearcode_Addshoppers_Block_Adminform::WRONG_CREDENTIAL; } elseif ($return['result'] == 1 || $return['result'] == 15 || $return['result'] == 10) { if ($return['result'] == 10) { if (isset($params['login']['login']) && isset($params['login']['password'])) { $message = "LOGIN_MISSING_PARAMETER"; $data = "login="******"&password="******"&url=" . $this->shopUrl . "&category=" . urlencode($config->getCategory()) . "&phone=" . urlencode($config->getPhone()) . "&platform=" . $this->platform . "&site_name=" . $this->shopName; $return = $this->sendRequestWithBasicAuth($this->api_url . '/login', $data); // $this->getResponse()->setBody(var_dump($return)); if (!isset($return['shopid'])) { $return['shopid'] = $config->getShopId(); } if (!isset($return['api_key'])) { $return['api_key'] = $config->getApiKey(); } $buttons_codes = $this->getButtonsCode($return['shopid'], $return['api_key']); $buttons_code_html = ''; if ($params['configuration']['social']) { $buttons_code_html = '<div style="float:right;">' . $buttons_codes['buttons']['button2'] . '</div>'; } if ($params['configuration']['opengraph']) { $buttons_code_html = $buttons_code_html . $buttons_codes['buttons']['open-graph']; } if ($buttons_code_html == '') { $buttons_code_html = $buttons_codes['buttons']['button1']; } if (!isset($buttons_codes['buttons']['button2'])) { $config->setApiKey('9NF-HtmcFlwYOCOCpRJRwv6smHChiubg'); $buttons_code_html = '<div class="share-buttons share-buttons-panel" data-style="medium" data-counter="true" data-oauth="true" data-hover="true" data-buttons="twitter,facebook,pinterest"></div><div style="float:right;"><div class="share-buttons-multi"><div class="share-buttons share-buttons-fb-like" data-style="standard"></div><div class="share-buttons share-buttons-og" data-action="want" data-counter="false"></div><div class="share-buttons share-buttons-og" data-action="own" data-counter="false"></div></div></div>'; } $config->setButtonsCode($buttons_code_html); $config->setActive(1); $config->setSocialEnabled($params['configuration']['social']); $config->setOpenGraphEnabled($params['configuration']['opengraph']); $config->setEmail($params['login']['login']); $config->setPassword($params['login']['password']); $config->setCategory($params['login']['category']); $config->setShopId($return['shopid']); $config->setApiKey($return['api_key']); $config->setUrl($this->shopUrl); $this->redirectBack($params['store']); } } if (isset($params['configuration']['use_schema'])) { $params['configuration']['use_schema'] = 1; } if (isset($params['configuration']['social'])) { $params['configuration']['social'] = 1; } if (isset($params['configuration']['opengraph'])) { $params['configuration']['opengraph'] = 1; } $config->setEnabled(1); $config->setSchemaEnabled($params['configuration']['use_schema']); $config->setApiKey($return['api_key']); $buttons_codes = $this->getButtonsCode($return['shopid'], $return['api_key']); $buttons_code_html = ''; if ($params['configuration']['social']) { $buttons_code_html = '<div style="float:right;">' . $buttons_codes['buttons']['button2'] . '</div>'; } if ($params['configuration']['opengraph']) { $buttons_code_html .= $buttons_codes['buttons']['open-graph']; } if ($buttons_code_html == '') { $buttons_code_html = $buttons_codes['buttons']['button1']; } $config->setButtonsCode($buttons_code_html); $config->setActive(1); $config->setSocialEnabled($params['configuration']['social']); $config->setOpenGraphEnabled($params['configuration']['opengraph']); $config->setEmail($params['login']['login']); $config->setPassword($params['login']['password']); $config->setCategory('Other'); $config->setShopId($return['shopid']); $config->setApiKey($return['api_key']); $config->setUrl($this->shopUrl); $message = 'AUTHENTICATED'; } else { $message = 'Unknown exception.'; } Mage::getSingleton('core/session')->setData('message', array('value' => $message)); Mage::app()->getCache()->clean(); $this->redirectBack($params['store']); }