Installation Add the package via Composer:
composer require bannister/user-bundle
Publish the bundle’s assets and configuration:
php bin/console bannister:install
First Use Case: User Registration
User entity (located in src/Entity/User.php by default) to add custom fields.config/routes.yaml (or via annotations):
bannister_user:
resource: "@BannisterUserBundle/Resources/config/routing.yaml"
/register (or your custom route).Key Configuration
Review config/packages/bannister_user.yaml for:
activation.enabled).reset.token_ttl).default_role).Custom User Fields
User entity (e.g., src/Entity/CustomUser extends User).phoneNumber, preferences) and update the database schema:
php bin/console make:migration
php bin/console doctrine:migrate
RegistrationType) to include new fields.Authentication Logic
AuthenticationSuccessHandler or AuthenticationFailureHandler services.# config/packages/security.yaml
firewalls:
main:
form_login:
default_target_path: bannister_user_dashboard
always_use_default_target_path: false
Email Templates
activation, reset) in:
templates/bannister_user/email/
{{ user.email }} or {{ resetToken }}.API Integration
/api/register, /api/reset-password) with JSON payloads.{
"email": "user@example.com",
"password": "securePassword123",
"customField": "value"
}
Event Listeners
UserRegisteredEvent, PasswordResetEvent) in services.yaml:
services:
App\EventListener\CustomUserListener:
tags:
- { name: kernel.event_listener, event: bannister.user.registered, method: onUserRegistered }
Database Schema Mismatches
User entity, always run migrations after adding fields to avoid ColumnNotFoundException.User class’s @ORM\Entity and @ORM\Table annotations match your database.Email Configuration
mailer_transport is set in .env (e.g., MAILER_DSN=smtp://user:pass@smtp.example.com).Password Hashing
UserPasswordHasherInterface. If customizing, ensure the hasher is properly configured in security.yaml:
security:
password_hashers:
App\Entity\User: 'auto'
Route Conflicts
/login, /register) may conflict with existing routes. Use _prefix in routing.yaml:
bannister_user:
resource: "@BannisterUserBundle/Resources/config/routing.yaml"
prefix: "/auth"
Activation Tokens
activation.token_ttl (default: 24 hours). Clear old tokens periodically:
php bin/console bannister:user:cleanup-tokens
Enable Debug Mode
Set APP_ENV=dev in .env to see detailed error messages and Twig debug output.
Log Events
Enable event logging in config/packages/monolog.yaml:
handlers:
main:
type: stream
level: debug
channels: ["!event"]
event:
type: stream
level: debug
channels: ["event"]
Check the User Provider
If authentication fails, verify the user_provider in security.yaml points to your extended User entity:
providers:
app_user_provider:
entity:
class: App\Entity\CustomUser
property: email
Custom Validation
Override the RegistrationType form class to add validation rules:
// src/Form/RegistrationType.php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('phoneNumber', TextType::class, [
'constraints' => [new NotBlank(), new Length(['min' => 10])]
]);
}
Custom Roles
Add roles dynamically in the User entity’s getRoles() method:
public function getRoles(): array
{
$roles = ['ROLE_USER'];
if ($this->isAdmin()) {
$roles[] = 'ROLE_ADMIN';
}
return array_unique($roles);
}
API Authentication
Extend the TokenAuthenticator for custom API token logic:
// src/Security/TokenAuthenticator.php
public function supports(Request $request)
{
return $request->headers->has('X-AUTH-TOKEN');
}
How can I help you explore Laravel packages today?