mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
add config change username card allow outside alphabets
This commit is contained in:
@@ -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 !");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user