diff --git a/assets/lib/Helpers/Config.php b/assets/lib/Helpers/Config.php index 48a97b0dea..f853c749ea 100644 --- a/assets/lib/Helpers/Config.php +++ b/assets/lib/Helpers/Config.php @@ -6,6 +6,7 @@ use jsonHelper; use APIhelpers; +use Exception; class Config { @@ -71,8 +72,11 @@ public function loadConfig($name) if ($this->fs->checkFile($configFile)) { $json = file_get_contents(MODX_BASE_PATH . $configFile); /** @var array $json */ - $json = jsonHelper::jsonDecode($json, array('assoc' => true), true); - $config = array_merge($config, $json); + $_json = jsonHelper::jsonDecode($json, array('assoc' => true), true); + if(empty($json) || empty($_json)) { + throw new Exception($configFile . ' is empty or has errors'); + } + $config = array_merge($config, $_json); } } diff --git a/assets/snippets/FormLister/core/controller/Profile.php b/assets/snippets/FormLister/core/controller/Profile.php index f6f1dea737..078a0e1bf6 100644 --- a/assets/snippets/FormLister/core/controller/Profile.php +++ b/assets/snippets/FormLister/core/controller/Profile.php @@ -174,7 +174,7 @@ public function process () if (isset($fields[$verificationField]) && $this->user->get($verificationField) != $fields[$verificationField]) { $fields['verified'] = 0; } - $result = $this->user->fromArray($fields)->save(true); + $result = (int)$this->user->fromArray($fields)->save(true); $this->log('Update profile', [ 'data' => $fields, 'result' => $result, diff --git a/assets/snippets/FormLister/core/controller/Register.php b/assets/snippets/FormLister/core/controller/Register.php index bef5be5808..34f96f1fb9 100644 --- a/assets/snippets/FormLister/core/controller/Register.php +++ b/assets/snippets/FormLister/core/controller/Register.php @@ -144,7 +144,7 @@ public function process () $this->addMessage($this->translate('register.registration_failed')); } else { $this->user->close(); - $userdata = $this->user->edit($result)->toArray(); + $userdata = $this->user->edit((int)$result)->toArray(); $this->setFields($userdata); if ($dob = $this->fromTimestamp($this->getField('dob'))) { $this->setField('dob', $dob); diff --git a/assets/snippets/FormLister/docs/history.md b/assets/snippets/FormLister/docs/history.md index 8f58481fd7..35224ca451 100644 --- a/assets/snippets/FormLister/docs/history.md +++ b/assets/snippets/FormLister/docs/history.md @@ -1,4 +1,7 @@ ## History +### 1.19.8 +* [Enhancement] Yandex SmartCaptcha (YandexCaptcha). + ### 1.19.6 * [Fix] Ошибка при выводе сообщений (Core). diff --git a/assets/snippets/FormLister/lib/captcha/yandexCaptcha/wrapper.php b/assets/snippets/FormLister/lib/captcha/yandexCaptcha/wrapper.php new file mode 100644 index 0000000000..2c355fff57 --- /dev/null +++ b/assets/snippets/FormLister/lib/captcha/yandexCaptcha/wrapper.php @@ -0,0 +1,91 @@ +cfg = $cfg; + $this->modx = $modx; + } + + /** + * Устанавливает значение капчи + * @return mixed + */ + public function init() + { + return; + } + + /** + * Плейсхолдер капчи для вывода в шаблон + * Может быть ссылкой на коннектор (чтобы можно было обновлять c помощью js), может быть сразу картинкой в base64 + * @return string + */ + public function getPlaceholder() + { + $siteKey = \APIhelpers::getkey($this->cfg, 'siteKey'); + $id = \APIhelpers::getkey($this->cfg, 'id'); + $id = $id ? ('id="' . $id . '-captcha"') : ''; + $out = ''; + if (!empty($siteKey)) { + $out = "
"; + } + + return $out; + } + + /** + * @param \FormLister\Core $FormLister + * @param $value + * @param \FormLister\CaptchaInterface $captcha + * @return bool|string + */ + public static function validate(Core $FormLister, $value, CaptchaInterface $captcha) + { + $secretKey = \APIhelpers::getkey($captcha->cfg, 'secretKey'); + $params = http_build_query([ + 'secret' => $secretKey, + 'token' => $value, + 'ip' => \APIhelpers::getUserIP() + ]); + $url = "https://smartcaptcha.yandexcloud.net/validate?{$params}"; + $out = false; + if (!empty($value)) { + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_TIMEOUT, 10); + curl_setopt($curl, CURLOPT_USERAGENT, + "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16"); + $response = curl_exec($curl); + curl_close($curl); + $response = json_decode($response, true) ?? []; + $out = isset($response['status']) && $response['status'] === 'ok'; + } + if (!$out) { + $out = \APIhelpers::getkey($captcha->cfg, 'errorCodeFailed', 'Вы не прошли проверку'); + } + $FormLister->log('YandexCaptcha validation result: ' . $out); + + return $out; + } +} diff --git a/install/assets/plugins/userHelper.tpl b/install/assets/plugins/userHelper.tpl index d3a2cc6c0a..ee0c9ad67b 100644 --- a/install/assets/plugins/userHelper.tpl +++ b/install/assets/plugins/userHelper.tpl @@ -5,7 +5,7 @@ * addition to FormLister * * @category plugin - * @version 1.19.7 + * @version 1.19.9 * @internal @properties &model=Model;text; &logoutKey=Request key;text;logout &cookieName=Cookie Name;text;WebLoginPE &cookieLifetime=Cookie Lifetime, seconds;text;157680000 &maxFails=Max failed logins;text;3 &blockTime=Block for, seconds;text;3600 &trackWebUserActivity=Track web user activity;list;No,Yes;No * @internal @events OnWebAuthentication,OnWebPageInit,OnPageNotFound,OnWebLogin,OnWebSaveUser,OnUserAuthentication,OnUserLogin,OnUserSave * @internal @modx_category Content diff --git a/install/assets/snippets/FormLister.tpl b/install/assets/snippets/FormLister.tpl index 66d4c5ca36..b6a6a75667 100644 --- a/install/assets/snippets/FormLister.tpl +++ b/install/assets/snippets/FormLister.tpl @@ -5,7 +5,7 @@ * Form processor * * @category snippet - * @version 1.19.7 + * @version 1.19.9 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL) * @internal @modx_category Content * @internal @installset base, sample