Installation
composer require akuma/user-bundle
Ensure akuma/core-bundle (≥1.0.4) is also installed (dependency).
Enable the Bundle
Add to config/bundles.php:
Akuma\UserBundle\AkumaUserBundle::class => ['all' => true],
First Use Case: User Registration
AkumaUserBundle base entity (if needed) by overriding User model in src/User/User.php:
namespace App\User;
use Akuma\UserBundle\Entity\User as BaseUser;
class User extends BaseUser { /* Custom fields/methods */ }
config/routes.yaml:
akuma_user:
resource: "@AkumaUserBundle/Resources/config/routing.yml"
prefix: /user
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
Authentication
fos_user integration:
# config/packages/security.yaml
security:
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
main:
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
routing.yml or override templates in templates/AkumaUserBundle/.User Roles & Permissions
fos_user roles (e.g., ROLE_ADMIN) or extend with Akuma’s core bundle:
// src/User/User.php
public function getRoles(): array
{
$roles = $this->roles;
$roles[] = 'ROLE_USER'; // Default role
return array_unique($roles);
}
Profile Management
User entity to add fields (e.g., avatar, bio):
// src/User/User.php
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $avatar;
src/Form/UserType.php) and controller to handle updates:
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class UserType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('avatar', FileType::class);
$builder->add('bio', TextType::class);
}
}
API Integration
# config/packages/serializer.yaml
framework:
serializer:
mapping:
paths: ['%kernel.project_dir%/config/serializer']
Create config/serializer/Akuma.UserBundle.yaml:
Akuma\UserBundle\Entity\User:
attributes:
id: ~
email: ~
roles: ~
Akuma\CoreBundle\Service\Logger) for logging user actions.fos_user.user_registered or fos_user.user_updated events:
// src/EventListener/UserListener.php
namespace App\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\FilterUserResponseEvent;
class UserListener implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
FOSUserEvents::REGISTRATION_COMPLETED => 'onRegistration',
];
}
public function onRegistration(FilterUserResponseEvent $event) {
// Send welcome email, etc.
}
}
vendor/akuma/user-bundle/Resources/views/ to templates/AkumaUserBundle/.Dependency Conflicts
fos_user-bundle (≥1.3) is a hard dependency. Ensure compatibility with your Symfony version (tested on Symfony 3.x/4.x).fos_user (e.g., deprecated UserManager methods).Migration Issues
User entity with fos_user fields (username, email, password). Custom migrations may break if fields are renamed.SchemaTool to compare schemas:
php bin/console doctrine:schema:update --dump-sql
Template Overrides
registration.html.twig must match the original path).{% extends 'AkumaUserBundle:Registration:registration.html.twig' %} in custom templates.CSRF Token Errors
csrf_token_generator is configured in security.yaml (as shown above).config/packages/dev/security.yaml:
security:
debug: true
// src/EventListener/UserLogger.php
use Psr\Log\LoggerInterface;
class UserLogger {
public function __construct(private LoggerInterface $logger) {}
public function logAction(User $user, string $action) {
$this->logger->info("User {$user->getEmail()} performed {$action}");
}
}
Custom User Provider
fos_user.user_provider.username_email to support custom logic:
security:
providers:
custom_user_provider:
id: App\Security\UserProvider
UserProviderInterface in src/Security/UserProvider.php.Two-Factor Authentication (2FA)
symfony/security or lexik/jwt-authentication-bundle:
composer require lexik/jwt-authentication-bundle
User entity to add twoFactorSecret.Social Logins
hwi/oauth-bundle and link to fos_user:
composer require hwi/oauth-bundle
config/packages/hwi_oauth.yaml to connect to fos_user provider.fos_user.registration.confirmation.enabled to false in config/packages/fos_user.yaml.fos_user.resetting.token_ttl (default: 86400 seconds).config/packages/vich_uploader.yaml if using VichUploaderBundle:
vich_uploader:
db_driver: orm
mappings:
user_avatar:
uri_prefix: /uploads/avatars
upload_destination: '%kernel.project_dir%/public/uploads/avatars'
How can I help you explore Laravel packages today?