sidus/user-bundle

User management for Symfony 6.3+

Maintainers

Package info

github.com/VincentChalnot/SidusUserBundle

pkg:composer/sidus/user-bundle

Transparency log

Statistics

Installs: 360

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

v3.0.0 2026-07-22 12:52 UTC

This package is auto-updated.

Last update: 2026-07-22 12:54:09 UTC


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.

Features

  • User and Group Doctrine entities (ULID identifiers, bigint PK, ROLE_USER / ROLE_ADMIN built 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/fr included).
  • Self-service profile edition and password change actions for authenticated users.
  • A role hierarchy service (Sidus\UserBundle\Security\Core\Role\RoleHierarchy) that exposes security.role_hierarchy.roles as 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 generated TemplatedEmail before sending.
  • Console commands to create, promote/demote and change the password of users without going through the UI.
  • AuthorableInterface + a Doctrine subscriber that auto-fills createdBy/updatedBy on 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's PasswordAuthenticatedUserInterface/UserInterface/EquatableInterface with role/admin helpers. Implement this (or reuse Entity\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\UserManager is the Doctrine-backed implementation).
  • Sidus\UserBundle\Model\AuthorableInterface — implement on any Doctrine entity to get createdBy/updatedBy auto-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.