Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Can't create new users via CLI if username is disabled #1076

Closed
sanchawebo opened this issue Mar 28, 2024 · 1 comment · Fixed by #1078
Closed

Bug: Can't create new users via CLI if username is disabled #1076

sanchawebo opened this issue Mar 28, 2024 · 1 comment · Fixed by #1078
Labels
bug Something isn't working

Comments

@sanchawebo
Copy link

PHP Version

8.3.3

CodeIgniter4 Version

4.4.6

Shield Version

1.0.2

Which operating systems have you tested for this bug?

macOS, Linux

Which server did you use?

apache

Database

MySQL 5.7, 10.5.22-MariaDB

Did you customize Shield?

I customized a lot of things primarily i disabled the username requirement for registration.

What happened?

When I try to create a new user via the CLI command spark shield:user create I get this error:

[ErrorException]
Undefined array key "username"
at VENDORPATH/codeigniter4/shield/src/Commands/User.php:245

Backtrace:
  1    VENDORPATH/codeigniter4/shield/src/Commands/User.php:245
       CodeIgniter\Debug\Exceptions()->errorHandler(2, 'Undefined array key "username"', '/PATH/vendor/codeigniter4/shield/src/Commands/User.php', 245)

  2    VENDORPATH/codeigniter4/shield/src/Commands/User.php:139
       CodeIgniter\Shield\Commands\User()->setValidationRules()

  3    SYSTEMPATH/CLI/Commands.php:65
       CodeIgniter\Shield\Commands\User()->run([...])

  4    SYSTEMPATH/CLI/Console.php:46
       CodeIgniter\CLI\Commands()->run('shield:user', [...])

  5    ROOTPATH/spark:102
       CodeIgniter\CLI\Console()->run()

Steps to Reproduce

Create a custom registration validation with no username requirement.
Then try to create a new user via CLI command.

Expected Output

Create a user without the need to supply a username.

Anything else?

The validation rules for CLI creation get pulled from this: vendor/codeigniter4/shield/src/Commands/User.php:221:$rules = $validationRules->getRegistrationRules(); but on line 245 it sets it like so

$this->validationRules = [
    'username' => $rules['username'],
    'email'    => $rules['email'],
    'password' => $rules['password'],
];
@sanchawebo sanchawebo added the bug Something isn't working label Mar 28, 2024
@kenjis
Copy link
Member

kenjis commented Mar 28, 2024

Please try #1078

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants