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')); } }
/** * @param Varien_Object $object * @return bool */ public function validate($object) { if ($password = $object->getPassword()) { if ($password == $object->getPasswordConfirm()) { return true; } } return parent::validate($object); }
protected function _checkPost($requireAccessToken = true) { if (Mage::helper('storealerts')->isDebug() || Mage::app()->getStore()->isCurrentlySecure()) { if ($data = $this->getRequest()->getPost()) { $dataObj = new Varien_Object(); $dataObj->setData($data); $deviceToken = $dataObj->getDeviceToken(); $name = $dataObj->getName(); $username = $dataObj->getUsername(); $password = $dataObj->getPassword(); $accessToken = $requireAccessToken ? $dataObj->getAccessToken() : true; if ($deviceToken && $username && $password && $accessToken) { $admin = Mage::helper('storealerts')->login($username, $password); if ($admin->getId()) { try { $datetime = date("Y-m-d H:i:s"); $preference = Mage::getModel('extensions_store_storealerts/preference'); $preference->load($admin->getId()); if (!$preference->getId()) { $preference->setUserId($admin->getId())->setCreatedAt($datetime)->setUpdatedAt($datetime)->save(); } $dataObj->setPreference($preference); $device = Mage::getModel('extensions_store_storealerts/device'); $device->load($deviceToken, 'device_token'); if (!$device->getId()) { $device->setName($name)->setDeviceToken($deviceToken)->setUserId($admin->getId())->setCreatedAt($datetime)->setUpdatedAt($datetime)->save(); } $dataObj->setDevice($device); $result['error'] = false; $result['data'] = $dataObj; } catch (Exception $e) { $result['error'] = true; $result['data'] = $e->getMessage(); } } else { $result['error'] = true; $result['data'] = 'Could not login admin'; } } else { $result['error'] = true; $result['data'] = 'No device token, username, password or access token.'; } } else { $result['error'] = true; $result['data'] = 'No admin login credentials posted.'; } } else { $result['error'] = true; $result['data'] = 'Request is not over HTTPS.'; } if ($result['error'] === true) { $errorMessage = $result['data']; Mage::helper('storealerts')->log($errorMessage); } return $result; }
/** * Initializes service from gateway * @param Varien_Object $gateway Object with all connection params * @return */ public function initFromVarienObject(Varien_Object $gateway) { $this->setType($gateway->getProtocol())->setHost($gateway->getHost())->setLogin($gateway->getLogin())->setPassword($gateway->getPassword())->setPort($gateway->getPort())->setSecure($this->_getGatewaySecure($gateway)); $instanceConstructor = $this->_getConnectionConstructor(); try { // Try to connect $this->setInstance(new $instanceConstructor($this->_getConnectionParams())); } catch (Zend_Mail_Protocol_Exception $e) { $this->log($e->getMessage()); return $e->getMessage(); } return true; }
public function download(Varien_Object $connectionInfo, $target) { $file = $connectionInfo->getFile(); $this->_log($this->_getLog()->__("Connecting to FTP server %s", $connectionInfo->getHost())); $ftp = new Varien_Io_Ftp(); $ftp->open(array('host' => $connectionInfo->getHost(), 'user' => $connectionInfo->getUsername(), 'password' => $connectionInfo->getPassword(), 'timeout' => $connectionInfo->hasTimeout() ? $connectionInfo->getTimeout() : 10, 'passive' => $connectionInfo->hasPassive() ? $connectionInfo->getPassive() : true, 'ssl' => $connectionInfo->hasSsl() ? $connectionInfo->getSsl() : null, 'file_mode' => $connectionInfo->hasFileMode() ? $connectionInfo->getFileMode() : null)); if (!is_writable(Mage::getBaseDir() . DS . $target)) { Mage::throwException($this->_getLog()->__("Can not write file %s to %s, folder not writable (doesn't exist?)", $connectionInfo->getFile(), $target)); } $this->_log($this->_getLog()->__("Downloading file %s from %s, to %s", $connectionInfo->getFile(), $connectionInfo->getHost(), $target)); $targetPath = $this->_getTargetPath($target, basename($file)); $ftp->read($file, $targetPath); $ftp->close(); }
/** * Return password based on choosen type * * @param Varien_Object $customer * @return string */ public function getPasswordFor(Varien_Object $customer) { $password = ''; switch ($this->getPasswordType()) { case Sitemaster_Checkout_Model_Source::PASSWORD_FIELD: $password = $customer->getPassword(); break; case Sitemaster_Checkout_Model_Source::PASSWORD_PHONE: $password = $customer->getAddress()->getTelephone(); $size = strlen($password); if ($size < 6) { $password .= $this->generateRandomKey(6 - $size); } break; } return empty($password) ? $this->generateRandomKey(8) : $password; }