/** * Run task * * @return void */ protected function doActionRun() { $event = \XLite\Core\Request::getInstance()->event; $result = false; $errors = array(); $task = \XLite\Core\Database::getRepo('XLite\\Model\\EventTask')->findOneBy(array('name' => $event)); if ($task) { if (\XLite\Core\EventListener::getInstance()->handle($task->getName(), $task->getArguments())) { \XLite\Core\Database::getEM()->remove($task); $result = true; } $errors = \XLite\Core\EventListener::getInstance()->getErrors(); } else { \XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->removeEventState($event); } \XLite\Core\Database::getEM()->flush(); $state = \XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->getEventState($event); $this->setPureAction(true); if ($result && $state) { \XLite\Core\Event::eventTaskRun(array('percent' => \XLite\Core\Database::getRepo('XLite\\Model\\TmpVar')->getEventStatePercent($event), 'error' => !empty($errors))); } else { $result = false; } if ($errors) { foreach ($errors as $message) { \XLite\Core\TopMessage::addError($message); } $result = false; } $this->valid = $result; }
/** * Update membership list * * @return void */ protected function doActionUpdate() { $data = \XLite\Core\Request::getInstance()->update_memberships; if (!is_array($data)) { // TODO - add top message } else { $code = $this->getCurrentLanguage(); $flag = false; foreach ($data as $id => $row) { $m = \XLite\Core\Database::getRepo('\\XLite\\Model\\Membership')->find($id); if ($m) { $duplicate = \XLite\Core\Database::getRepo('\\XLite\\Model\\Membership')->createQueryBuilder()->andWhere('translations.name = :name', 'm.membership_id != :id')->setParameter('name', $row['name'])->setParameter('id', $id)->setMaxResults(1)->getSingleResult(); if (!is_null($duplicate)) { \XLite\Core\TopMessage::addWarning('"' . $row['name'] . '" ' . ' membership name is already in use. ' . 'Please specify another name for this membership level'); } else { \XLite\Core\Database::getRepo('\\XLite\\Model\\Membership')->update($m, $row); } $flag = true; } else { \XLite\Core\TopMessage::addError('Could not find membership ID#' . $id . ' record in the database'); } } if ($flag) { \XLite\Core\Database::getEM()->flush(); } } }
/** * Update payment method * * @return void */ protected function doActionUpdate() { $settings = \XLite\Core\Request::getInstance()->settings; $method = $this->getPaymentMethod(); if (!$method) { \XLite\Core\TopMessage::addError('An attempt to update settings of unknown payment method'); } else { if (is_array($settings)) { foreach ($settings as $name => $value) { $method->setSetting($name, trim($value)); } } $properties = \XLite\Core\Request::getInstance()->properties; if (is_array($properties) && !empty($properties)) { $method->map($properties); } \XLite\Core\Database::getRepo('\\XLite\\Model\\Payment\\Method')->update($method); // If "just added" method is configured and can be enabled then we enable it if (\XLite\Core\Request::getInstance()->just_added && $method->isConfigured() && $method->canEnable()) { $method->setEnabled(true); \XLite\Core\Database::getEM()->flush(); } if ($method->isConfigured()) { \XLite\Core\TopMessage::addInfo('The settings of payment method successfully updated'); $this->setReturnURL($this->buildURL('payment_settings')); } else { \XLite\Core\TopMessage::addWarning('Payment method has not been configured properly'); } } }
/** * Prevent users registering by administrator * * @return void */ public function handleRequest() { if ($this->isRegisterMode() || 'delete' === \XLite\Core\Request::getInstance()->action) { \XLite\Core\TopMessage::addError('It is impossible to delete or create user accounts because your store currently works ' . 'as an integration with Drupal and shares users with Drupal. Deleting/creating user ' . 'accounts is possible via Drupal administrator interface.'); $this->markAsAccessDenied(); } return parent::handleRequest(); }
/** * Preprocessor for no-action run * * @return void */ protected function doNoAction() { $this->restoreOrder(); if ($this->addedOrder) { $reason = $this->addedOrder->getFailureReason() ?: $this->getDefaultFailureReason(); \XLite\Core\TopMessage::addError($reason); } }
/** * Do action * * @return void */ protected function doActionConfirmWithPassword() { $password = \XLite\Core\Request::getInstance()->password; $result = null !== $password && \XLite\Core\Auth::comparePassword(\XLite\Core\Auth::getInstance()->getProfile()->getPassword(), $password); if (!$result) { \XLite\Core\TopMessage::addError('Incorrect password. Please try again.'); } \XLite\Core\Event::passwordConfirmed(array('result' => $result)); }
/** * doActionDelete * * @return void * @throws */ protected function doActionDelete() { if (\Includes\Utils\FileManager::isExists($this->sqldumpFile) && !\Includes\Utils\FileManager::deleteFile($this->sqldumpFile)) { \XLite\Core\TopMessage::addError(static::t('Unable to delete file') . ' ' . $this->sqldumpFile); } else { \XLite\Core\TopMessage::addInfo('SQL file was deleted successfully'); } $this->doRedirect(); }
/** * Check amazon S3 settings * * @return void */ protected function checkAmazonS3Settings() { $config = \XLite\Core\Config::getInstance()->CDev->AmazonS3Images; if (!function_exists('curl_init')) { \XLite\Core\TopMessage::addError('This module uses PHP\'s cURL functions which are disabled on your web server'); } elseif ($config->access_key && $config->secret_key && !\XLite\Module\CDev\AmazonS3Images\Core\S3::getInstance()->isValid()) { \XLite\Core\TopMessage::addWarning('Connection to Amazon S3 failed.' . ' Check whether the AWS Access key и AWS Secret key specified in the module settings are correct.'); } }
/** * Request probe script * * @return void */ protected function requestProbe() { $url = \XLite::getInstance()->getShopURL(\XLite\Core\Converter::buildURL('', '', array('key' => \XLite\Core\Config::getInstance()->Internal->probe_key), 'probe.php')); set_time_limit(0); $request = new \XLite\Core\HTTP\Request($url); $response = $request->sendRequest(); if (200 != $response->code) { \XLite\Core\TopMessage::addError('Measuring productivity in manual mode failed.'); } }
/** * Do redirect customer to iDEAL server for payment * * @return void */ protected function doActionTransaction() { try { $processor = new \XLite\Module\XC\IdealPayments\Model\Payment\Processor\IdealProfessional(); $processor->doTransactionRequest(\XLite\Core\Request::getInstance()->iid, \XLite\Core\Request::getInstance()->transid); } catch (\Exception $e) { \XLite\Core\TopMessage::addError(static::t('Something wrong in the iDEAL payment module settings. Please try later or use other payment option.')); $this->setReturnURL('checkout'); } }
/** * doActionRecoverPassword * * @return void */ protected function doActionRecoverPassword() { // show recover message if email is valid if ($this->requestRecoverPassword($this->get('email'))) { $this->setReturnURL($this->buildURL('recover_password', '', array('mode' => 'recoverMessage', 'link_mailed' => 1, 'email' => $this->get('email')))); } else { $this->setReturnURL($this->buildURL('recover_password', '', array('valid' => 0))); \XLite\Core\TopMessage::addError('There is no user with specified email address'); } }
/** * Do action * * @return void */ protected function doActionConfirmWithPassword() { $password = \XLite\Core\Request::getInstance()->password; $result = null !== $password && \XLite\Core\Auth::comparePassword(\XLite\Core\Auth::getInstance()->getProfile()->getPassword(), $password); if ($result) { echo 1; } else { \XLite\Core\TopMessage::addError('Incorrect password. Please try again.'); echo 0; } }
/** * Return current module object * * @return \XLite\Model\Module * @throws \Exception */ public function getModule() { if (!isset($this->module)) { $this->module = \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->find($this->getModuleID()); if (!$this->module) { \XLite\Core\TopMessage::addError('Add-on does not exist.'); \XLite\Logger::getInstance()->log('Add-on does not exist (ID: ' . $this->getModuleID() . ')', LOG_ERR); $this->redirect($this->buildURL('addons_list_installed')); } } return $this->module; }
/** * Action 'import' * * @return void */ protected function doActionImport() { $fileName = \XLite\Core\Session::getInstance()->language_import_file; if (\Includes\Utils\FileManager::isExists($fileName)) { $result = \XLite\Core\Database::getRepo('XLite\\Model\\Language')->parseImportFile($fileName, true); \XLite\Core\Session::getInstance()->language_import_result = $result; } else { \XLite\Core\Session::getInstance()->language_import_file = null; \XLite\Core\TopMessage::addError('File not found'); } $this->setReturnURL($this->buildURL('languages')); }
/** * Set sale price parameters for products list * * @return void */ protected function doActionSetSalePrice() { $form = new \XLite\Module\CDev\Sale\View\Form\SaleSelectedDialog(); $form->getRequestData(); if ($form->getValidationMessage()) { \XLite\Core\TopMessage::addError($form->getValidationMessage()); } else { \XLite\Core\Database::getRepo('\\XLite\\Model\\Product')->updateInBatchById($this->getUpdateInfo()); \XLite\Core\TopMessage::addInfo('Products information has been successfully updated'); } $this->setReturnURL($this->buildURL('product_list', '', array('mode' => 'search'))); }
protected function getFormURL() { $this->callEbanxLib(); $params = array(); $params = $this->getFormFields(); $response = \Ebanx\Ebanx::doRequest($params); if ($response->status == 'SUCCESS') { $checkoutURL = $response->redirect_url; } else { \XLite\Core\TopMessage::addError('Erro processando pagamento! EBANX: ' . $response->status_code . ": " . $response->status_message); return; } return $checkoutURL; }
/** * Remove file * * @return void */ protected function doActionRemoveAttachment() { $attachment = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\FileAttachments\\Model\\Product\\Attachment')->find(\XLite\Core\Request::getInstance()->id); if ($attachment) { $attachment->getProduct()->getAttachments()->removeElement($attachment); \XLite\Core\Database::getEM()->remove($attachment); \XLite\Core\TopMessage::addInfo('Attachment has been deleted successfully'); $this->setPureAction(true); } else { $this->valid = false; \XLite\Core\TopMessage::addError('Attachment is not deleted'); } \XLite\Core\Database::getEM()->flush(); }
/** * Renew egood link * * @return void */ protected function doActionEgoodsRenew() { $id = \XLite\Core\Request::GetInstance()->attachment_id; $attachment = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\Egoods\\Model\\OrderItem\\PrivateAttachment')->find($id); if (!$attachment) { \XLite\Core\TopMessage::addError('Download link did not found'); } elseif (!$attachment->isActive()) { \XLite\Core\TopMessage::addError('Download link is not active'); } else { $attachment->renew(); \XLite\Core\Database::getEM()->flush(); \XLite\Core\Mailer::sendEgoodsLinks($attachment->getItem()->getOrder()); \XLite\Core\TopMessage::addInfo('Download link is renew'); } }
/** * Login * * @return void */ protected function doActionLogin() { $profile = \XLite\Core\Auth::getInstance()->loginAdministrator(\XLite\Core\Request::getInstance()->login, \XLite\Core\Request::getInstance()->password); if (is_int($profile) && \XLite\Core\Auth::RESULT_ACCESS_DENIED === $profile) { $this->set('valid', false); \XLite\Core\TopMessage::addError('Invalid login or password'); $returnURL = $this->buildURL('login'); } elseif (isset(\XLite\Core\Session::getInstance()->lastWorkingURL)) { $returnURL = \XLite\Core\Session::getInstance()->get('lastWorkingURL'); \XLite\Core\Session::getInstance()->set('lastWorkingURL', null); } else { $returnURL = $this->buildURL(); } $this->setReturnURL($returnURL); }
/** * Common handler for pin codes import * * @param string $methodToLoad Method to use for getting file * @param array $paramsToLoad Parameters to use in getter method * * @return void */ protected function doActionSelectImportPinCodes($methodToLoad, array $paramsToLoad) { \XLite\Core\Session::getInstance()->importPinCodesCell = null; $methodToLoad .= 'Import'; $path = call_user_func_array(array($this, $methodToLoad), $paramsToLoad); if (is_array($path)) { if (!$path[0] && $path[1]) { \XLite\Core\TopMessage::addError($path[1]); } $path = $path[0]; } if ($path) { chmod($path, 0644); \XLite\Core\Session::getInstance()->pinCodesImportFile = $path; } }
/** * Return zone * * @return \XLite\Model\Zone */ public function getZone() { if (!isset($this->zone)) { if (isset(\XLite\Core\Request::getInstance()->zone_id)) { $zone = \XLite\Core\Database::getRepo('XLite\\Model\\Zone')->find(\XLite\Core\Request::getInstance()->zone_id); if (!isset($zone)) { \XLite\Core\TopMessage::addError('Requested zone does not exists'); } else { $this->zone = $zone; } } else { $this->zone = new \XLite\Model\Zone(); } } return $this->zone; }
/** * Perform login action * * @return void */ protected function doActionLogin() { $loginApi = new \XLite\Module\CDev\Paypal\Core\Login(); $requestProcessed = false; $returnURL = ''; \XLite\Module\CDev\Paypal\Main::addLog('Login return', \XLite\Core\Request::getInstance()->getData()); if ($loginApi->checkRequest()) { $accessToken = $loginApi->createFromAuthorisationCode(\XLite\Core\Request::getInstance()->code); $profileInfo = isset($accessToken['access_token']) ? $loginApi->getUserinfo($accessToken['access_token']) : null; if ($profileInfo && !empty($profileInfo['user_id']) && !empty($profileInfo['email'])) { $profile = $this->getSocialLoginProfile($profileInfo['email'], 'PayPal', $profileInfo['user_id'], $profileInfo); if ($profile) { if ($profile->isEnabled()) { \XLite\Core\Auth::getInstance()->loginProfile($profile); $accessToken['expirationTime'] = LC_START_TIME + $accessToken['expires_in']; \XLite\Core\Session::getInstance()->paypalAccessToken = $accessToken; // We merge the logged in cart into the session cart $profileCart = $this->getCart(); $profileCart->login($profile); \XLite\Core\Database::getEM()->flush(); if ($profileCart->isPersistent()) { $this->updateCart(); } $returnURL = $this->getAuthReturnURL(); } else { \XLite\Core\TopMessage::addError('Profile is disabled'); $returnURL = $this->getAuthReturnURL(true); } } else { $provider = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findOneBy(array('login' => $profileInfo['email'], 'order' => null))->getSocialLoginProvider(); if ($provider) { $signInVia = 'Please sign in with ' . $provider . '.'; } else { $signInVia = 'Profile with the same e-mail address already registered. ' . 'Please sign in the classic way.'; } \XLite\Core\TopMessage::addError($signInVia); $returnURL = $this->getAuthReturnURL(true); } $requestProcessed = true; } } if (!$requestProcessed) { \XLite\Core\TopMessage::addError('We were unable to process this request'); $returnURL = ''; } $this->closePopup($returnURL); }
/** * Common handler for page images. * * @param string $methodToLoad Method to use for getting images * @param array $paramsToLoad Parameters to use in image getter method * * @return void * @see ____func_see____ * @since 1.0.7 */ protected function doActionSelectPageImage($methodToLoad, array $paramsToLoad) { $pageId = intval(\XLite\Core\Request::getInstance()->objectId); $page = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\SimpleCMS\\Model\\Page')->find($pageId); $image = $page->getImage(); if (!$image) { $image = new \XLite\Module\CDev\SimpleCMS\Model\Image\Page\Image(); } if (call_user_func_array(array($image, $methodToLoad), $paramsToLoad)) { $image->setPage($page); $page->setImage($image); \XLite\Core\Database::getEM()->persist($image); \XLite\Core\Database::getEM()->flush(); \XLite\Core\TopMessage::addInfo('The image has been updated'); } else { \XLite\Core\TopMessage::addError('Failed to update page image'); } }
/** * Update payment method * * @return void */ protected function doActionUpdate() { $settings = \XLite\Core\Request::getInstance()->settings; $m = $this->getPaymentMethod(); if (!$m) { \XLite\Core\TopMessage::addError('An attempt to update settings of unknown payment method'); } else { if (is_array($settings)) { foreach ($settings as $name => $value) { $m->setSetting($name, $value); } } $properties = \XLite\Core\Request::getInstance()->properties; if (is_array($properties) && !empty($properties)) { $m->map($properties); } \XLite\Core\Database::getRepo('\\XLite\\Model\\Payment\\Method')->update($m); \XLite\Core\TopMessage::addInfo('The settings of payment method successfully updated'); $this->setReturnURL($this->buildURL('payment_settings')); } }
/** * Perform login action * * @return void */ protected function doActionLogin() { $authProviders = \XLite\Module\CDev\SocialLogin\Core\AuthManager::getAuthProviders(); $requestProcessed = false; foreach ($authProviders as $authProvider) { if ($authProvider->detectAuth()) { $profileInfo = $authProvider->processAuth(); if ($profileInfo && !empty($profileInfo['id']) && !empty($profileInfo['email'])) { $profile = $this->getSocialLoginProfile($profileInfo['email'], $authProvider->getName(), $profileInfo['id']); if ($profile) { if ($profile->isEnabled()) { \XLite\Core\Auth::getInstance()->loginProfile($profile); $this->setAuthReturnURL($authProvider::STATE_PARAM_NAME); } else { \XLite\Core\TopMessage::addError('Profile is disabled'); $this->setAuthReturnURL($authProvider::STATE_PARAM_NAME, true); } } else { $provider = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findOneBy(array('login' => $profileInfo['email'], 'order' => null))->getSocialLoginProvider(); if ($provider) { $signInVia = 'Please sign in with ' . $provider . '.'; } else { $signInVia = 'Profile with the same e-mail address already registered. ' . 'Please sign in the classic way.'; } \XLite\Core\TopMessage::addError($signInVia); $this->setAuthReturnURL($authProvider::STATE_PARAM_NAME, true); } $requestProcessed = true; } } } if (!$requestProcessed) { \XLite\Core\TopMessage::addError('We were unable to process this request'); $this->setAuthReturnURL('', true); } }
/** * Update custom images * * @return void */ protected function updateCustomImages() { $dir = \XLite\Module\XC\ThemeTweaker\Main::getThemeDir() . 'images' . LC_DS; if ($_FILES && $_FILES['new_images'] && $_FILES['new_images']['name']) { if (!\Includes\Utils\FileManager::isExists($dir)) { \Includes\Utils\FileManager::mkdirRecursive($dir); } if (\Includes\Utils\FileManager::isDirWriteable($dir)) { foreach ($_FILES['new_images']['name'] as $i => $data) { \Includes\Utils\FileManager::moveUploadedFileByMultiple('new_images', $i, $dir); } } else { \XLite\Core\TopMessage::addError('The directory {{dir}} does not exist or is not writable.', array('dir' => $dir)); } } $delete = \XLite\Core\Request::getInstance()->delete; if ($delete && is_array($delete)) { foreach ($delete as $file => $del) { if ($del) { \Includes\Utils\FileManager::deleteFile($dir . $file); } } } }
/** * Process the errors occurred during the "validateInput" action * * @return void */ protected function postprocessErrorActionValidateInput() { \XLite\Core\TopMessage::addError($this->getErrorActionValidateInputMessage($this->getRequestData('login'))); }
/** * Add error top message 'Email already exists...' * * @return void */ protected function addErrorEmailExists() { \XLite\Core\TopMessage::addError('This e-mail address is already in use by another user.'); }
/** * Recover password * * @param string $email Profile email * @param string $requestID Request ID * * @return boolean */ protected function doPasswordRecovery($email, $requestID) { $result = false; $profile = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findByLogin($email); if (!isset($profile) || $profile->isAdmin()) { \XLite\Core\TopMessage::addError('There is no user with specified email address'); } elseif ($profile->getPasswordResetKey() != $requestID || \XLite\Core\Converter::time() > $profile->getPasswordResetKeyDate()) { \XLite\Core\TopMessage::addError('Your "Password reset key" has expired. Please enter the email address associated with your user account to get a new "Password reset key".'); $profile->setPasswordResetKey(''); $profile->setPasswordResetKeyDate(0); $profile->update(); } else { $pass = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->generatePassword(); $profile->setPassword(\XLite\Core\Auth::encryptPassword($pass)); $profile->setForceChangePassword(true); $profile->setPasswordResetKey(''); $profile->setPasswordResetKeyDate(0); $result = $profile->update(); if ($result) { $successfullyLogged = \XLite\Core\Auth::getInstance()->loginProfile($profile); if ($successfullyLogged) { $profileCart = $this->getCart(); // We merge the logged in cart into the session cart $profileCart->login($profile); \XLite\Core\Database::getEM()->flush(); if ($profileCart->isPersistent()) { $this->updateCart(); \XLite\Core\Event::getInstance()->exclude('updateCart'); } } } } return $result; }
/** * Preprocessor for no-action run * * @return void */ protected function doNoAction() { $this->restoreOrder(); \XLite\Core\TopMessage::addError('Sorry, your order payment is canceled.'); }