Skip to content

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

Closed
@sanchawebo

Description

@sanchawebo

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'],
];

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions