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

creatissimo/user-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require creatissimo/user-bundle
    

    Ensure your config/bundles.php includes:

    Creatissimo\UserBundle\CreatissimoUserBundle::class => ['all' => true],
    
  2. Database Configuration Run migrations (if using Doctrine):

    php bin/console doctrine:migrations:diff
    php bin/console doctrine:migrations:migrate
    
  3. First Use Case: Registration

    • Enable registration in config/packages/creatissimo_user.yaml:
      fos_user:
          registration:
              form:
                  type: App\Form\RegistrationType
      
    • Create a custom registration form (app/src/Form/RegistrationType.php):
      use Symfony\Component\Form\AbstractType;
      use Symfony\Component\Form\FormBuilderInterface;
      
      class RegistrationType extends AbstractType {
          public function buildForm(FormBuilderInterface $builder, array $options) {
              $builder->add('email');
              $builder->add('password');
          }
      }
      
  4. Routing Ensure routes are loaded in config/routes.yaml:

    fos_user:
        resource: "@CreatissimoUserBundle/Resources/config/routing/all.xml"
        prefix: /user
    

Implementation Patterns

Core Workflows

  1. User Management

    • Create/Update Users:
      $user = new User();
      $user->setEmail('[email protected]');
      $user->setPlainPassword('secure123');
      $userManager = $this->get('fos_user.user_manager');
      $userManager->updateUser($user);
      
    • Load User by Email:
      $user = $userManager->findUserBy(['email' => '[email protected]']);
      
  2. Password Handling

    • Reset Password Flow:
      • Trigger via /user/resetting/request.
      • Customize token generation in UserManager:
        $tokenGenerator = $this->get('fos_user.util.token_generator');
        $token = $tokenGenerator->generateToken();
        
  3. Custom User Fields

    • Extend the User entity:
      use Creatissimo\UserBundle\Model\User as BaseUser;
      
      class User extends BaseUser {
          /**
           * @ORM\Column(type="string", length=255)
           */
          private $customField;
      }
      
    • Update the form type and registration handler accordingly.
  4. Authentication Integration

    • Use the bundle’s UserProvider with Symfony’s SecurityBundle:
      security:
          providers:
              fos_userbundle:
                  id: fos_user.user_provider.username_email
      

Common Integrations

  • APIs: Use fos_user with API Platform or custom controllers to expose user endpoints.
  • Frontend: Pair with Vue/React via Symfony’s Mercure or REST APIs.
  • Admin Panels: Integrate with EasyAdmin or SonataAdmin for CRUD operations.

Gotchas and Tips

Pitfalls

  1. Deprecated Fork

    • This is a fork of FOSUserBundle (last updated 2021), not actively maintained. Prefer the official FOSUserBundle for new projects.
    • Risk: Bugs or compatibility issues with newer Symfony/Laravel versions.
  2. Configuration Overrides

    • Custom configurations (e.g., fos_user.yaml) may conflict with Symfony’s default security setup.
    • Fix: Always test in a staging environment before production.
  3. Token Expiry

    • Password reset tokens expire by default (1 day). Customize in config/packages/creatissimo_user.yaml:
      fos_user:
          resetting:
              token_ttl: 86400 # 1 day in seconds
      
  4. Email Confirmation

    • If using email confirmation, ensure your User entity implements AdvancedUserInterface:
      use Creatissimo\UserBundle\Model\AdvancedUserInterface;
      class User implements AdvancedUserInterface { ... }
      

Debugging Tips

  1. Event Listeners

    • Override default behaviors via events (e.g., fos_user.register.form.validate):
      // src/EventListener/RegistrationListener.php
      public function onRegistrationFormValidate(FormEvent $event) {
          $form = $event->getForm();
          $form->addError(new FormError('Custom validation error'));
      }
      
    • Register in services.yaml:
      services:
          App\EventListener\RegistrationListener:
              tags:
                  - { name: kernel.event_listener, event: fos_user.register.form.validate }
      
  2. Doctrine Migrations

    • If migrations fail, drop and recreate the database or manually adjust the schema.
  3. Logging

    • Enable debug mode (APP_DEBUG=true) to log FOSUserBundle events:
      $this->get('logger')->debug('User event triggered', ['event' => $event->getName()]);
      

Extension Points

  1. Custom User Class

    • Override the default User entity by configuring fos_user.model.user.class:
      fos_user:
          model:
              user:
                  class: App\Entity\User
      
  2. Profile Management

    • Extend the profile controller:
      class ProfileController extends AbstractController {
          public function editAction() {
              $user = $this->getUser();
              $form = $this->createForm('App\Form\ProfileType', $user);
              // ...
          }
      }
      
    • Update routes in routing.yml:
      app_profile_edit:
          path: /profile/edit
          methods: [GET, POST]
          defaults: { _controller: App\Controller\ProfileController::edit }
      
  3. Security Voters

    • Add custom voters for role-based access:
      use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
      
      class CustomVoter implements VoterInterface {
          public function supports(string $attribute, $subject): bool { ... }
          public function vote(AuthorizationContext $context): int { ... }
      }
      
    • Register in security.yaml:
      security:
          access_control:
              - { path: ^/admin, roles: ROLE_ADMIN }
      
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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle