Skip to content

Commit

Permalink
update snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathologic committed May 20, 2023
1 parent 1ca7193 commit 94a1b64
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 6 deletions.
8 changes: 6 additions & 2 deletions assets/lib/Helpers/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use jsonHelper;
use APIhelpers;
use Exception;

class Config
{
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion assets/snippets/FormLister/core/controller/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion assets/snippets/FormLister/core/controller/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions assets/snippets/FormLister/docs/history.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## History
### 1.19.8
* [Enhancement] Yandex SmartCaptcha (YandexCaptcha).

### 1.19.6
* [Fix] Ошибка при выводе сообщений (Core).

Expand Down
91 changes: 91 additions & 0 deletions assets/snippets/FormLister/lib/captcha/yandexCaptcha/wrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

use FormLister\CaptchaInterface;
use FormLister\Core;

/**
* Class ReCaptchaWrapper
*/
class YandexCaptchaWrapper implements CaptchaInterface
{
/**
* @var array $cfg
* id, secretKey, siteKey
*/
public $cfg = null;
protected $modx = null;

/**
* modxCaptchaWrapper constructor.
* @param $modx
* @param $cfg
*/
public function __construct(\DocumentParser $modx, $cfg = [])
{
$this->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 = "<div {$id} data-sitekey=\"{$siteKey}\" class=\"smart-captcha\"></div>";
}

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;
}
}
2 changes: 1 addition & 1 deletion install/assets/plugins/userHelper.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion install/assets/snippets/FormLister.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 94a1b64

Please sign in to comment.