Installation
Since this is a fork of FOSUserBundle tailored for Kimai 2, it is not meant for standalone use. However, if you're working with Kimai 2 or need a lightweight FOSUser alternative, add it via Composer:
composer require comunedifirenze/user-bundle
(Note: Verify compatibility with your Symfony version—this bundle drops FOSUserBundle deprecations.)
Configuration Publish the default config (if needed):
php bin/console fos:user:setup
(Check config/packages/security.yaml and config/packages/user.yaml for required adjustments.)
First Use Case
templates/FOSUserBundle/Registration/.ForgotPassword controller (if not removed in future versions).Custom User Model
Extend the default User entity (likely App\Entity\User) by adding fields:
// src/Entity/User.php
use ComuneDI\Bundle\UserBundle\Model\User as BaseUser;
class User extends BaseUser
{
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $customField;
}
Update the bundle’s UserProvider to recognize your model.
Authentication & Security
fos_user firewall:
# config/packages/security.yaml
firewalls:
main:
form_login:
provider: fos_userbundle
security.yaml.Event Listeners
Hook into user lifecycle events (e.g., UserRegistered, PasswordReset):
// src/EventListener/UserListener.php
use ComuneDI\Bundle\UserBundle\Event\UserEvent;
class UserListener
{
public function onUserRegistered(UserEvent $event)
{
$user = $event->getUser();
// Custom logic (e.g., send welcome email via Symfony Mailer).
}
}
Register in services.yaml:
services:
App\EventListener\UserListener:
tags:
- { name: kernel.event_listener, event: fos_user.user_registered, method: onUserRegistered }
API Integration
For API-based auth (e.g., JWT), pair with lexik/jwt-authentication-bundle:
# config/packages/security.yaml
firewalls:
api:
pattern: ^/api
stateless: true
jwt: ~
templates/FOSUserBundle/ (e.g., registration.html.twig).use Symfony\Component\Validator\Constraints as Assert;
class User extends BaseUser
{
/**
* @Assert\NotBlank
*/
private $customField;
}
php bin/console make:migration
php bin/console doctrine:migrations:migrate
No Standalone Support
Deprecated FOSUserBundle Features
UserManager) may be renamed or removed. Refer to the CHANGELOG for changes.Mailer Dependency
use Symfony\Component\Mailer\MailerInterface;
class UserListener
{
public function __construct(private MailerInterface $mailer) {}
public function onPasswordReset(UserEvent $event)
{
$this->mailer->send(...);
}
}
Route Conflicts
/register, /resetting) may clash with other bundles. Override them in config/routes.yaml:
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
prefix: /auth
config/packages/dev/security.yaml to debug auth issues:
security:
debug: true
public function onUserRegistered(UserEvent $event)
{
error_log('User registered: ' . $event->getUser()->getEmail());
}
fos_user table:
php bin/console doctrine:query:sql "SELECT * FROM fos_user"
Custom User Provider Override the default provider for complex logic:
# config/packages/security.yaml
providers:
app_user_provider:
id: App\Security\UserProvider
// src/Security/UserProvider.php
use ComuneDI\Bundle\UserBundle\Model\UserInterface;
class UserProvider implements UserProviderInterface
{
public function loadUserByUsername(string $username): UserInterface
{
// Custom logic (e.g., LDAP integration).
}
}
API Tokens
For token-based auth, integrate with api-platform or nelmio/api-doc-bundle:
# config/packages/api_platform.yaml
resources:
App\Entity\User:
properties:
token: ['get']
Testing
Use Symfony’s WebTestCase to test user flows:
public function testRegistration()
{
$client = static::createClient();
$crawler = $client->request('GET', '/auth/register');
// Assert form fields, etc.
}
How can I help you explore Laravel packages today?