sidus / user-bundle
User management for Symfony 6.3+
Requires
- php: >=8.1
- doctrine/orm: >=2.9
- symfony/console: >=6.3
- symfony/dependency-injection: >=6.3
- symfony/http-foundation: >=6.3
- symfony/http-kernel: >=6.3
- symfony/messenger: >=6.3
- symfony/options-resolver: >=6.3
- symfony/password-hasher: >=6.3
- symfony/security-core: >=6.3
- symfony/translation: >=6.3
- symfony/uid: >=6.3
- symfony/validator: >=6.3
Requires (Dev)
- egulias/email-validator: ^4.0
- phpunit/phpunit: ^10.5
- symfony/form: >=6.3
- symfony/mime: >=6.3
Suggests
- sidus/admin-bundle: Required for admin (enable_admin: true, the default) — provides the Sidus\AdminBundle\* classes used by Action\Admin\*
- sidus/template-bundle: Required for admin
- symfony/form: Required for the login, profile, lost/reset password and admin forms
- symfony/mailer: Required to send mail to users (account creation, password reset)
- symfony/mime: Required to send mail to users (account creation, password reset)
- symfony/routing: Required for admin
- symfony/twig-bridge: Required to send mail to users (account creation, password reset)
README
User management for Symfony 6.3+: authentication, password reset/recovery, user profile
editing, roles/permissions with a proper hierarchy tree, and optional group management —
plus an optional CRUD admin backend when sidus/admin-bundle is available.
- License: MIT
- Author: Vincent Chalnot (sidus.fr)
- Repository: https://github.com/VincentChalnot/SidusUserBundle
Features
UserandGroupDoctrine entities (ULID identifiers, bigint PK,ROLE_USER/ROLE_ADMINbuilt in, many-to-many groups).- Login / logout, "lost password", and "reset password" flows out of the box, each with
HTML views and translated flash messages (
en/frincluded). - Self-service profile edition and password change actions for authenticated users.
- A role hierarchy service (
Sidus\UserBundle\Security\Core\Role\RoleHierarchy) that exposessecurity.role_hierarchy.rolesas a browsable tree (LeafRole), used by the role-picker form type. - Transactional email (new account + password reset) via
symfony/mailer, with an event (MailEvent) to customize the generatedTemplatedEmailbefore sending. - Console commands to create, promote/demote and change the password of users without going through the UI.
AuthorableInterface+ a Doctrine subscriber that auto-fillscreatedBy/updatedByon any entity that implements it.- Optional admin CRUD screens for users/groups, built on
sidus/admin-bundle.
Requirements
- PHP >= 8.1
- Symfony >= 6.3 (
dependency-injection,http-foundation,http-kernel,security-core,translation,console,uid,validator,options-resolver,password-hasher) doctrine/orm>= 2.9
Optional, depending on which features you use:
symfony/mailer+symfony/mime— sending account/reset emails.symfony/form— all the bundle's forms (login, profile, password, roles...).symfony/routing+symfony/twig-bridge+sidus/template-bundle+sidus/admin-bundle— the admin backend (enable_admin: true).
Installation
composer require sidus/user-bundle
Register the bundle (skip if you use Symfony Flex, which does this automatically):
// config/bundles.php Sidus\UserBundle\SidusUserBundle::class => ['all' => true],
The bundle prepends its own Doctrine attribute mapping and (when
sidus/template-bundle is present) registers its login/lost-password/reset-password/
profile templates with sidus_template — no extra Doctrine or template config needed.
Update your schema (or generate a migration) once User/Group are mapped:
php bin/console doctrine:schema:update --force
# or, with doctrine-migrations-bundle:
php bin/console make:migration
Configuration
# config/packages/sidus_user.yaml sidus_user: home_route: app_home # route to redirect to once authenticated (required, used everywhere) company_title: 'Acme Corp' # shown in transactional emails (required) enable_admin: true # load the admin CRUD routes/services (default: true) mailer: from_email: no-reply@example.com from_name: 'Acme Corp' support_email: support@example.com support_name: 'Acme Support' templates: new_user: html: '@SidusUser/Email/newUser.html.twig' text: '@SidusUser/Email/newUser.txt.twig' reset_password: html: '@SidusUser/Email/resetPassword.html.twig' text: '@SidusUser/Email/resetPassword.txt.twig'
mailer.* is required as soon as the mailer key is present — the extension loads
Resources/config/mailer.yaml (registering UserMailer) only if the section is set, so
omit it entirely for setups that never send mail (e.g. admin-created users with a
manually assigned password).
Wire the security firewall to the bundle's routes and to Doctrine's user provider, e.g.:
# config/packages/security.yaml security: password_hashers: Sidus\UserBundle\Entity\User: auto providers: sidus_user: entity: class: Sidus\UserBundle\Entity\User property: email firewalls: main: provider: sidus_user form_login: login_path: sidus.user.login check_path: sidus.user.login_check logout: path: sidus.user.logout role_hierarchy: ROLE_ADMIN: ROLE_USER
Import the routes:
# config/routes/sidus_user.yaml sidus_user: resource: '@SidusUserBundle/Resources/config/routes.yaml'
Routes
| Name | Path | Purpose |
|---|---|---|
sidus.user.login |
/login |
Login form |
sidus.user.login_check |
/login_check |
Firewall check target (intercepted by form_login; falls back to redirecting to sidus.user.login if hit directly) |
sidus.user.logout |
/logout |
Firewall logout target |
sidus.user.lost_password |
/login/lost-password |
Request a password reset email |
sidus.user.reset_password |
/login/reset-password |
Consume the reset token, set a new password |
sidus.user.profile |
/profile |
Edit own email/profile |
sidus.user.profile.change_password |
/profile/change-password |
Change own password |
Admin routes are provided by Resources/config/admin.yaml (Action\Admin\*) and only
tag the controllers as services — actual route definitions/registration are driven by
sidus/admin-bundle's own admin configuration, which is out of scope for this bundle.
Console commands
php bin/console sidus:user:create [username] [--password=] [--admin] [--if-not-exists] php bin/console sidus:user:promote [username] [--demote] php bin/console sidus:user:change-password [username] [--password=]
All arguments/options are prompted interactively when omitted (non-interactive shells
require them explicitly). Leaving --password blank triggers a "reset password" email
request instead of setting a password directly.
Domain model
Sidus\UserBundle\Model\AdvancedUserInterface— extends Symfony'sPasswordAuthenticatedUserInterface/UserInterface/EquatableInterfacewith role/admin helpers. Implement this (or reuseEntity\User+Entity\RoleCollectionTrait) if you need a custom user entity.Sidus\UserBundle\Domain\Manager\UserManagerInterface— the single entry point for creating/persisting users, hashing passwords, and issuing password-reset requests (Infrastructure\Manager\UserManageris the Doctrine-backed implementation).Sidus\UserBundle\Model\AuthorableInterface— implement on any Doctrine entity to getcreatedBy/updatedByauto-populated from the current security token (Event\AuthorableSubscriber).Sidus\UserBundle\Model\Event\MailEvent— dispatched before every transactional email is sent; listen to it to add headers, attachments, or override recipients.
License
MIT — see LICENSE.