From 901e7ae77b0e0c8f3f313b694d776474ab0efe0b Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Sat, 30 Mar 2024 14:49:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=AB=99=E7=82=B9=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E9=AA=8C=E8=AF=81=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/SiteConfig.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/models/SiteConfig.php b/models/SiteConfig.php index 0068af8..3d24f41 100644 --- a/models/SiteConfig.php +++ b/models/SiteConfig.php @@ -30,8 +30,30 @@ class SiteConfig extends Model public function rules(): array { return [ - [['siteTitle', 'siteUrl', 'domain', 'verifyProvider', 'recaptchaSiteKey', 'recaptchaSecret', 'hcaptchaSiteKey', 'hcaptchaSecret', 'turnstileSiteKey', 'turnstileSecret', 'ipinfoToken'], 'string'], + [['siteTitle', 'domain'], 'required'], + [['siteTitle', 'domain', 'verifyProvider', 'recaptchaSiteKey', 'recaptchaSecret', 'hcaptchaSiteKey', 'hcaptchaSecret', 'turnstileSiteKey', 'turnstileSecret', 'ipinfoToken'], 'string'], [['registrationEnabled', 'enableIpinfo'], 'boolean'], + ['verifyProvider', 'in', 'range' => ['reCAPTCHA', 'hCaptcha', 'Turnstile', 'None']], + [['recaptchaSiteKey', 'recaptchaSecret'], 'required', 'when' => function ($model) { + return $model->verifyProvider == 'reCAPTCHA'; + }, 'whenClient' => "function (attribute, value) { + return $('#siteconfig-verifyprovider').val() == 'reCAPTCHA'; + }"], + [['hcaptchaSiteKey', 'hcaptchaSecret'], 'required', 'when' => function ($model) { + return $model->verifyProvider == 'hCaptcha'; + }, 'whenClient' => "function (attribute, value) { + return $('#siteconfig-verifyprovider').val() == 'hCaptcha'; + }"], + [['turnstileSiteKey', 'turnstileSecret'], 'required', 'when' => function ($model) { + return $model->verifyProvider == 'Turnstile'; + }, 'whenClient' => "function (attribute, value) { + return $('#siteconfig-verifyprovider').val() == 'Turnstile'; + }"], + ['ipinfoToken', 'required', 'when' => function ($model) { + return $model->enableIpinfo; + }, 'whenClient' => "function (attribute, value) { + return $('#siteconfig-enableipinfo').is(':checked'); + }"], ]; } @@ -86,7 +108,7 @@ class SiteConfig extends Model { try { $env = parse_ini_file(Yii::getAlias('@app/.env')); - if($env === false) { + if ($env === false) { return false; } $env['SITE_TITLE'] = $this->siteTitle; @@ -104,7 +126,7 @@ class SiteConfig extends Model $data = array_map(function ($key, $value) { return "$key=$value"; }, array_keys($env), $env); - return !(file_put_contents('.env', implode("\n", $data)) == false); + return !(file_put_contents(Yii::getAlias('@app/.env'), implode("\n", $data)) == false); } catch (Exception) { return false; }