Skip to content

Commit

Permalink
fix create user
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Aug 21, 2023
1 parent 21c4ca0 commit a64fee6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Filament/Resources/User/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function form(Form $form): Form
Forms\Components\TextInput::make('password')->password()->required()->visibleOn(Pages\CreateUser::class),
Forms\Components\TextInput::make('password_confirmation')->password()->required()->same('password')->visibleOn(Pages\CreateUser::class),
Forms\Components\TextInput::make('id')->integer(),
Forms\Components\Select::make('class')->options(array_column(User::$classes, 'text')),
Forms\Components\Select::make('class')->options(User::listClass(User::CLASS_PEASANT, Auth::user()->class - 1)),
]);
}

Expand Down
11 changes: 10 additions & 1 deletion app/Repositories/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,16 @@ public function store(array $params)
if (mb_strlen($password) < 6 || mb_strlen($password) > 40) {
throw new \InvalidArgumentException("Invalid password: $password, it should be more than 6 character and less than 40 character");
}
$class = !empty($params['class']) ? intval($params['class']) : User::CLASS_USER;
if (!empty($params['class'])) {
$class =intval($params['class']);
$authUser = Auth::user();
if ($authUser && $class >= $authUser->class) {
throw new InsufficientPermissionException('No permission');
}
} else {
$class = User::CLASS_USER;
}

if (!isset(User::$classes[$class])) {
throw new \InvalidArgumentException("Invalid user class: $class");
}
Expand Down
4 changes: 2 additions & 2 deletions include/constants.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.6');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-08-18');
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.7');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-08-22');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
Expand Down

0 comments on commit a64fee6

Please sign in to comment.