Installation Add the bundle to your Symfony project via Composer:
composer require chebur/login-form-bundle
Enable the bundle in config/bundles.php:
Chebur\LoginFormBundle\CheburLoginFormBundle::class => ['all' => true],
Configuration Publish the default config:
php bin/console chebur:login-form:install
Update config/packages/chebur_login_form.yaml with your security provider (e.g., security.user.provider.concrete).
First Use Case Use the provided Twig extension to render the login form in a template:
{{ render(chebur_login_form('app.login')) }}
Ensure you have a route (app.login) pointing to a controller handling the form submission.
Form Customization
Extend the default form behavior by overriding the form type in config/packages/chebur_login_form.yaml:
chebur_login_form:
form_type: App\Form\CustomLoginType
Create a custom form type extending Chebur\LoginFormBundle\Form\LoginType.
Authentication Workflow Handle login logic in a controller:
use Chebur\LoginFormBundle\Security\LoginFormAuthenticator;
public function login(LoginFormAuthenticator $authenticator, Request $request)
{
return $authenticator->authenticate($request);
}
CSRF Protection The bundle auto-generates CSRF tokens. Ensure your form includes:
{{ form_row(form._token) }}
Flash Messages Use Symfony’s flash system for success/error messages:
$this->addFlash('success', 'Login successful!');
Integration with Security
Configure the firewall in config/packages/security.yaml:
firewalls:
main:
form_login:
provider: app.user_provider
authenticator: Chebur\LoginFormBundle\Security\LoginFormAuthenticator
Deprecated Symfony Version The bundle was last updated in 2019 and may not support Symfony 6+. Test thoroughly or fork the package for compatibility.
Missing Documentation
The README is minimal. Refer to the Symfony Security Component for advanced use cases.
CSRF Token Mismatch If tokens fail, clear cache:
php bin/console cache:clear
Form Type Overrides
Ensure your custom form type extends the correct base class (Chebur\LoginFormBundle\Form\LoginType) to avoid missing fields (e.g., _csrf_token).
Enable Debug Mode
Set APP_DEBUG=true in .env to log form submission errors.
Check Event Listeners
The bundle dispatches chebur.login_form.submit events. Subscribe to debug submission data:
// src/EventListener/LoginDebugListener.php
public function onLoginSubmit(LoginFormEvent $event) {
dump($event->getData());
}
Database Queries
Use Symfony’s profiler (/profiler) to verify user provider queries during login.
Custom Authenticators
Extend LoginFormAuthenticator to add logic (e.g., 2FA):
class CustomAuthenticator extends LoginFormAuthenticator {
public function checkCredentials($credentials) {
// Custom validation
}
}
Twig Extensions
Override the render() method in Chebur\LoginFormBundle\Twig\LoginFormExtension for custom templates.
Configuration Overrides Dynamically adjust form options via dependency injection:
services:
Chebur\LoginFormBundle\Form\LoginType:
arguments:
$rememberMe: '%kernel.debug%'
How can I help you explore Laravel packages today?