Weave Code
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

User Bundle Laravel Package

bengor-user/user-bundle

Fully featured, well-tested Symfony user bundle built on BenGorUser. Supports multiple user types and HTML/JSON renderers. Includes registration (confirmation/invites), login/logout, JWT auth, password reset, user removal, role management, and token purging.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require bengor-user/user-bundle
    

    Enable the bundle in AppKernel.php:

    new BenGorUser\UserBundle\BenGorUserBundle(),
    
  2. Basic Configuration Define your user entity extending BenGorUser\User\Domain\Model\User:

    // src/AppBundle/Entity/User.php
    namespace AppBundle\Entity;
    use BenGorUser\User\Domain\Model\User as BaseUser;
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * @ORM\Entity
     */
    class User extends BaseUser {}
    

    Configure the bundle in config.yml:

    ben_gor_user:
        user_class:
            user:
                class: AppBundle\Entity\User
                firewall: main
    
  3. Security Configuration Update security.yml:

    security:
        encoders:
            AppBundle\Entity\User: bcrypt
        providers:
            bengor_user:
                id: bengor_user.user.provider
        firewalls:
            main:
                anonymous: ~
                pattern: ^/
                guard:
                    authenticators:
                        - bengor_user.user.form_login_authenticator
                form_login:
                    check_path: bengor_user_user_login_check
                    login_path: bengor_user_user_login
                logout: true
    
  4. First Use Case Access the default registration route at /user/sign-up or login at /user/login.


Implementation Patterns

Core Workflows

  1. User Registration

    • Basic: Use the default registration form at /user/sign-up.
    • With Confirmation: Configure in config.yml:
      ben_gor_user:
          registration:
              strategy: confirmation
      
    • By Invitation: Configure in config.yml:
      ben_gor_user:
          registration:
              strategy: invitation
      
  2. Password Management

    • Change Password: Use the default route /user/change-password.
    • Without Old Password: Configure in config.yml:
      ben_gor_user:
          password_change:
              strategy: without_old_password
      
    • Remember Password: Configure in config.yml:
      ben_gor_user:
          password_change:
              strategy: remember_password
      
  3. Authentication

    • Form Login: Default routes are auto-generated (/user/login, /user/logout).
    • JWT Authentication: Enable in config.yml:
      ben_gor_user:
          jwt_authentication: true
      
  4. Role Management

    • Grant/Revoke roles via the RoleManager service:
      $roleManager = $this->get('bengor_user.user.role_manager');
      $roleManager->grantRole('ROLE_ADMIN', $user);
      
  5. Multiple User Types

    • Define additional user classes in config.yml:
      ben_gor_user:
          user_class:
              user:
                  class: AppBundle\Entity\User
                  firewall: main
              employee:
                  class: AppBundle\Entity\Employee
                  firewall: employee
      
    • Configure separate firewalls, providers, and routes for each type.

Integration Tips

  • Custom Forms: Extend the default form types (SignUpType, LoginType) by creating custom form classes and overriding the services in services.yml.
  • Event Subscribers: Listen to events like UserRegisteredEvent or UserEnabledEvent for custom logic.
  • Console Commands: Use built-in commands for token cleanup:
    php bin/console ben-gor-user:purge-outdated-invitation-tokens
    

Gotchas and Tips

Common Pitfalls

  1. Route Conflicts

    • Ensure custom routes do not conflict with default bundle routes. Use extending_customize_urls.md to override routes.
  2. Doctrine ORM vs. ODM

    • For MongoDB, ensure DoctrineODMMongoDBBridgeBundle is installed and configured. The persistence key in config.yml must be set to doctrine_odm_mongodb.
  3. Firewall Configuration

    • Forgetting to configure the firewall key in user_class will result in authentication failures. Example:
      ben_gor_user:
          user_class:
              user:
                  class: AppBundle\Entity\User
                  firewall: main  # <-- Required
      
  4. Token Expiry

    • Outdated tokens (invitation, remember password) are not purged automatically. Run the console command manually or set up a cron job:
      php bin/console ben-gor-user:purge-outdated-invitation-tokens
      php bin/console ben-gor-user:purge-outdated-remember-password-tokens
      
  5. Multiple User Types and Roles

    • Roles are scoped to the user type. Granting ROLE_ADMIN to a User entity won’t affect an Employee entity unless explicitly granted.

Debugging Tips

  • Enable Debug Mode: Symfony’s debug toolbar provides insights into authentication and bundle events.
  • Check Events: Use the debug:event-dispatcher command to list available events:
    php bin/console debug:event-dispatcher
    
  • Log Events: Subscribe to events in a debug subscriber to log user actions:
    use BenGorUser\User\Domain\Event\UserRegisteredEvent;
    
    public function onUserRegistered(UserRegisteredEvent $event)
    {
        $this->logger->info('User registered', ['user' => $event->getUser()->getEmail()]);
    }
    

Extension Points

  1. Custom Use Cases

    • Create custom use cases by extending BenGorUser\User\Domain\UseCase\UseCase and register them as services.
  2. Custom Views

    • Override Twig templates by copying them from BenGorUserBundle/Resources/views/ to your project’s templates/BenGorUser/ directory.
  3. Adapters

    • Replace the default bus, mailer, or persistence adapters by configuring custom services in services.yml. Refer to adapters_buses.md, adapters_mailers.md, and adapters_persistence.md.
  4. Configuration Overrides

    • All configuration options can be overridden in config.yml. Use the reference_configuration.md for a full list of available options.

Performance Considerations

  • Token Cleanup: Schedule token purging during low-traffic periods to avoid performance impacts.
  • Caching: Leverage Symfony’s cache system for role management if dealing with large user bases.
  • MongoDB: Ensure proper indexing in MongoDB for user queries to avoid slow performance.

Legacy Notes

  • PHP 7 Compatibility: The bundle is not fully compatible with PHP 7 for MongoDB ODM. Use PHP 5.5–5.6 for MongoDB setups.
  • Last Release: The last release was in 2017. Monitor for updates or fork the repository if critical bugs arise.
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui