Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Standard User Command Bundle Laravel Package

aldaflux/standard-user-command-bundle

Symfony bundle adding console commands to manage application users: list registered users with a configurable result limit, create regular or admin accounts interactively or via arguments, and change an existing user's password by username or email.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require aldaflux/standard-user-command-bundle
    

    Ensure your project uses Symfony 7.1+ (check composer.json under "require").

  2. Enable the Bundle: Add to config/bundles.php:

    return [
        // ...
        Aldaflux\StandardUserCommandBundle\AldafluxStandardUserCommandBundle::class => ['all' => true],
    ];
    
  3. First Use Case: List existing users (requires a User entity with username/password fields):

    ./bin/console suc:user:list
    

Implementation Patterns

Core Workflows

  1. User Management:

    • Add Users:

      ./bin/console suc:user:add username email password --roles=ROLE_USER
      

      Tip: Use --roles for bulk role assignment (e.g., ROLE_ADMIN,ROLE_USER).

    • Password Updates:

      ./bin/console suc:user:change-password username new_password
      

      Partial args: Omit username to prompt interactively.

  2. Integration with Symfony Security:

    • Ensure your User entity extends Symfony\Component\Security\Core\User\UserInterface (or UserInterface + PasswordAuthenticatedUserInterface).
    • Example entity:
      // src/Entity/User.php
      namespace App\Entity;
      use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
      use Doctrine\ORM\Mapping as ORM;
      
      #[ORM\Entity]
      class User implements PasswordAuthenticatedUserInterface
      {
          #[ORM\Column]
          private string $username;
          #[ORM\Column]
          private string $password;
          // ...
      }
      
  3. Customization:

    • Override commands via command decorators (Symfony’s CommandBus pattern).
    • Extend the bundle’s UserManager service (if needed) by binding your own implementation.

Gotchas and Tips

Pitfalls

  1. Entity Mismatch:

    • The bundle assumes a User entity with username/password fields. Error: No such column: user.username → Verify your entity matches the expected schema.
  2. Password Hashing:

    • The bundle does not auto-hash passwords. Use Symfony’s PasswordHasherInterface in your User entity’s setPassword():
      public function setPassword(string $plainPassword): void
      {
          $this->password = $this->passwordHasher->hashPassword($this, $plainPassword);
      }
      
  3. Command Arguments:

    • No validation for add/change-password commands. Validate inputs manually or extend the command class.

Debugging Tips

  • Dry Runs: Use --dry-run flag (if supported) to preview changes before execution.
  • Logging: Enable debug mode (APP_DEBUG=1) to see SQL queries and command execution flow.

Extension Points

  1. Custom Fields: Add fields to the add command by extending the AddUserCommand class:

    // src/Command/CustomAddUserCommand.php
    namespace App\Command;
    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputArgument;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    
    class CustomAddUserCommand extends Command
    {
        protected function configure(): void
        {
            $this->addArgument('custom_field', InputArgument::OPTIONAL, 'Custom user field');
        }
        // ...
    }
    
  2. Event Listeners: Hook into user creation/modification via Symfony events (e.g., kernel.request or custom events).

  3. Configuration: Override bundle defaults in config/packages/aldaflux_standard_user_command.yaml:

    aldaflux_standard_user_command:
        default_roles: [ROLE_USER]
        password_hasher: 'app.password_hasher' # Custom hasher service
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log