refactor(web): remove forced language setting

go
codex 4 weeks ago
parent 313e52a0b1
commit 02591ee937

@ -47,7 +47,6 @@ class ConfigController extends AdminController
CloudIpChangeBillingService::DEFAULT_PRICE,
CloudProvisioningBillingConfig::PAYMENT_WINDOW_MINUTES_KEY =>
(string) CloudProvisioningBillingConfig::DEFAULT_PAYMENT_WINDOW_MINUTES,
'language' => 'false',
'host_1' => '',
'host_2' => '',
'host_3' => '',

@ -31,6 +31,7 @@ use App\Models\EmailVerify;
class AuthController extends BaseController
{
private $language = 'false';
private $login_forbidden_ips = '';
private $enable_login_email_verify = 'false';
private $login_session_ttl = 2592000;
@ -81,9 +82,6 @@ class AuthController extends BaseController
$this->enable_invite_code = $redis->get('enable_invite_code', 60, function () {
return Configurations::where('name', 'enable_invite_code')->value('value');
});
$this->language = $redis->get('language', 60, function () {
return Configurations::where('name', 'language')->value('value');
});
$this->login_forbidden_ips = $redis->get('login_forbidden_ips', 60, function () {
$value = Configurations::where('name', 'login_forbidden_ips')->value('value');
return $value === null ? '' : $value;

@ -18,6 +18,7 @@ use App\Utils\Tools;
*/
class HomeController extends BaseController
{
protected $language = 'false';
public function __construct()
{
@ -47,9 +48,6 @@ class HomeController extends BaseController
$this->seo = $redis->get('seo', 60, function () {
return Configurations::where('name', 'seo')->value('value');
});
$this->language = $redis->get('language', 60, function () {
return Configurations::where('name', 'language')->value('value');
});
$this->appName = Config::get('appName');
}

@ -3,9 +3,7 @@
namespace App\Controllers;
use App\Models\User;
use App\Models\Configurations;
use App\Services\CaptchaConfig;
use App\Services\RedisClient;
use App\Models\PasswordReset;
use App\Services\Password;
use App\Utils\Hash;
@ -24,11 +22,6 @@ class PasswordController extends BaseController
public function __construct()
{
$this->applyDomainTheme($this->getDomainConfigurations());
$redis = new RedisClient();
$this->language = $redis->get('language', 60, function () {
$value = Configurations::where('name', 'language')->value('value');
return $value === null ? 'false' : $value;
});
}
public function reset()

@ -32,20 +32,6 @@ class RegistrationIpRestriction
return $value === 'true';
}
public static function configuredEnglish(): bool
{
try {
$redis = new RedisClient();
$value = $redis->get('language', 60, static function () {
return self::databaseValue('language', 'false');
});
} catch (\Throwable $exception) {
$value = self::databaseValue('language', 'false');
}
return $value === 'true';
}
/** @return ?string One of the DENY_* codes, or null when registration is allowed. */
public static function denialForRequest($request, bool $enabled, ?callable $lookup = null): ?string
{

@ -292,13 +292,6 @@
</select>
<div class="form-text">关闭时保留历史返利记录,但新充值不生成返利。</div>
</div>
<div class="col-md-6">
<label class="form-label" for="language">英文落地页</label>
<select class="form-select" id="language" name="language">
<option value="true">开启</option>
<option value="false">关闭</option>
</select>
</div>
<div class="col-md-6">
<label class="form-label" for="verifyEmailType">注册验证邮件域名白名单</label>
<select class="form-select" id="verifyEmailType" name="verifyEmailType">

@ -0,0 +1,42 @@
<?php
$root = dirname(__DIR__, 2);
$read = static function (string $path) use ($root): string {
$content = file_get_contents($root . '/' . $path);
if ($content === false) {
throw new RuntimeException('Cannot read ' . $path);
}
return $content;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$adminTemplate = $read('web/resources/views/venix/admin/config.tpl');
$adminController = $read('web/app/Controllers/Admin/ConfigController.php');
$assert(!str_contains($adminTemplate, 'name="language"')
&& !str_contains($adminTemplate, 'id="language"')
&& !str_contains($adminTemplate, '英文落地页'),
'The retired administrator language toggle is still visible.');
$assert(!preg_match("/'language'\\s*=>/", $adminController),
'The retired language key is still writable through the administrator configuration API.');
foreach ([
'web/app/Controllers/HomeController.php',
'web/app/Controllers/AuthController.php',
'web/app/Controllers/PasswordController.php',
'web/app/Services/RegistrationIpRestriction.php',
] as $path) {
$source = $read($path);
$assert(!str_contains($source, "get('language'")
&& !str_contains($source, "where('name', 'language')"),
'The retired global language configuration is still read by ' . $path . '.');
}
$registrationRestriction = $read('web/app/Services/RegistrationIpRestriction.php');
$assert(!str_contains($registrationRestriction, 'configuredEnglish'),
'The retired registration language configuration helper is still present.');
echo "Administrator forced-language removal contract passed.\n";
Loading…
Cancel
Save