add config change username card allow outside alphabets

This commit is contained in:
xiaomlove
2022-08-11 18:26:11 +08:00
parent 9332b676b4
commit 8071efd487
5 changed files with 30 additions and 2 deletions

View File

@@ -118,6 +118,16 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
Forms\Components\TextInput::make('seed_box.max_uploaded')->label(__('label.setting.seed_box.max_uploaded'))->helperText(__('label.setting.seed_box.max_uploaded_help'))->integer(),
])->columns(2);
$tabs[] = Forms\Components\Tabs\Tab::make(__('label.setting.system.tab_header'))
->id('system')
->schema([
Forms\Components\Radio::make('system.change_username_card_allow_characters_outside_the_alphabets')
->options(self::$yesOrNo)
->inline(true)
->label(__('label.setting.system.change_username_card_allow_characters_outside_the_alphabets'))
,
])->columns(2);
$tabs = apply_filter('nexus_setting_tabs', $tabs);
return $tabs;
}

View File

@@ -400,7 +400,10 @@ class UserRepository extends BaseRepository
$user = User::query()->findOrFail($uid, User::$commonFields);
if ($metaKey == UserMeta::META_KEY_CHANGE_USERNAME) {
NexusDB::transaction(function () use ($user, $meta, $params) {
$this->changeUsername($user, UsernameChangeLog::CHANGE_TYPE_USER, $user, $params['username']);
$this->changeUsername(
$user, UsernameChangeLog::CHANGE_TYPE_USER, $user, $params['username'],
Setting::get('system.change_username_card_allow_characters_outside_the_alphabets') == 'yes'
);
$meta->delete();
clear_user_cache($user->id, $user->passkey);
});
@@ -410,7 +413,7 @@ class UserRepository extends BaseRepository
throw new \InvalidArgumentException("Invalid meta_key: $metaKey");
}
private function changeUsername($operator, $changeType, $targetUser, $newUsername): bool
private function changeUsername($operator, $changeType, $targetUser, $newUsername, $allowOutsideAlphabets = false): bool
{
$operator = $this->getUser($operator);
$targetUser = $this->getUser($targetUser);
@@ -422,6 +425,9 @@ class UserRepository extends BaseRepository
if ($strWidth < 4 || $strWidth > 20) {
throw new \InvalidArgumentException("Invalid username, maybe too long or too short");
}
if (!$allowOutsideAlphabets && !validusername($newUsername)) {
throw new \InvalidArgumentException("Invalid username, only support alphabets");
}
if (User::query()->where('username', $newUsername)->where('id', '!=', $targetUser->id)->exists()) {
throw new \RuntimeException("Username: $newUsername already exists !");
}

View File

@@ -72,6 +72,10 @@ return [
'not_seed_box_max_speed' => 'Not SeedBox max upload speed',
'not_seed_box_max_speed_help' => 'Unit: Mbps, if this value is exceeded and the SeedBox record cannot be matched, download permission is disabled',
],
'system' => [
'tab_header' => 'System',
'change_username_card_allow_characters_outside_the_alphabets' => 'Does the name change card allow characters other than English letters',
],
],
'user' => [
'label' => 'User',

View File

@@ -72,6 +72,10 @@ return [
'not_seed_box_max_speed' => '非 SeedBox 最高限速',
'not_seed_box_max_speed_help' => '单位Mbps。若超过此值又不能匹配 SeedBox 记录,禁用下载权限',
],
'system' => [
'tab_header' => '系统',
'change_username_card_allow_characters_outside_the_alphabets' => '改名卡是否允许英文字母外的字符',
],
],
'user' => [
'label' => '用户',

View File

@@ -72,6 +72,10 @@ return [
'not_seed_box_max_speed' => '非 SeedBox 最高限速',
'not_seed_box_max_speed_help' => '單位Mbps。若超過此值又不能匹配 SeedBox 記錄,禁用下載權限',
],
'system' => [
'tab_header' => '系統',
'change_username_card_allow_characters_outside_the_alphabets' => '改名卡是否允許英文字母外的字符',
],
],
'user' => [
'label' => '用戶',