Installation
Add the bundle to your composer.json:
composer require cekurte/userbundle
Enable it in config/bundles.php:
return [
// ...
Cekurte\UserBundle\CekurteUserBundle::class => ['all' => true],
];
Database Setup Run migrations (if using Doctrine):
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
The bundle extends FOSUserBundle, so ensure your User entity extends Cekurte\UserBundle\Entity\User.
First Use Case Register a new user via the built-in registration form (Bootstrap 3 templates included):
php bin/console fos:user:create
Access /register in your browser to test the registration flow.
Resources/doc/index.md for setup and configuration.Resources/views/FOSUserBundle/ (override these in your project).Resources/config/routing.yml (extend or override as needed).User Management
php bin/console fos:user:create --super-admin # Admin user
php bin/console fos:user:list # List users
Cekurte\UserBundle\Entity\User:
use Cekurte\UserBundle\Entity\User as BaseUser;
class User extends BaseUser {
// Add custom fields/methods
}
OAuth Integration (HWIOAuthBundle)
hwioauth_bundle in config/packages/hwioauth_bundle.yaml:
hwioauth_bundle:
resources:
- "CekurteUserBundle::oauth"
config/packages/cekurte_user.yaml:
cekurte_user:
oauth:
facebook:
app_id: "your_app_id"
app_secret: "your_secret"
/login/check-{provider} route (e.g., /login/check-facebook).Template Overrides Override Bootstrap 3 templates by copying files from:
vendor/cekurte/userbundle/Resources/views/FOSUserBundle/
to:
templates/FOSUserBundle/
Example: Override registration.html.twig for custom styling.
Event Listeners
Extend functionality via Symfony events (e.g., fos_user_registered):
// src/EventListener/UserListener.php
namespace App\EventListener;
use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class UserListener implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
FOSUserEvents::REGISTERED => 'onUserRegistered',
];
}
public function onUserRegistered($event) {
// Custom logic (e.g., send welcome email)
}
}
security.yaml includes the bundle’s firewall:
firewalls:
main:
form_login:
provider: fos_userbundle
logout: true
anonymous: true
base.html.twig:
{{ encore_entry_link_tags('app') }}
{{ cekurte_user_assets() }} {# If bundle provides helper #}
config/routes.yaml:
cekurte_user:
resource: "@CekurteUserBundle/Resources/config/routing.yml"
prefix: /
Namespace Conflicts
FOSUserBundle. If you’re using a custom User entity, ensure it only extends Cekurte\UserBundle\Entity\User (not FOS\UserBundle\Model\User directly).php bin/console cache:clear
OAuth Misconfiguration
composer require hwioauth/bundle).ServiceNotFoundException for OAuth services.hwioauth_bundle is enabled in bundles.php and config is correct.Template Caching
php bin/console assets:install
php bin/console cache:clear
Deprecated FOSUserBundle Methods
FOSUserBundle updates. Check the FOSUserBundle docs for breaking changes.Enable Debug Mode
Set APP_DEBUG=true in .env to see detailed errors (e.g., OAuth failures).
Check Logs
var/log/dev.log (look for HWI entries).fos_user logging in config/packages/monolog.yaml:
handlers:
fos_user:
type: stream
path: "%kernel.logs_dir%/fos_user.log"
level: debug
channels: ["fos_user"]
Common Errors
/register: Missing route or template. Verify routing.yml and template paths.app_id/app_secret in cekurte_user.yaml.{{ csrf_token('fos_user_registration_register') }} is in forms.Custom User Fields
Add fields to the User entity and update the form type:
// src/Form/RegistrationFormType.php
namespace App\Form;
use Cekurte\UserBundle\Form\Type\RegistrationFormType as BaseType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class RegistrationFormType extends BaseType {
public function buildForm(FormBuilderInterface $builder, array $options) {
parent::buildForm($builder, $options);
$builder->add('custom_field', TextType::class);
}
}
Update services.yaml to override the form:
services:
App\Form\RegistrationFormType: ~
Custom OAuth Providers Extend HWIOAuthBundle’s provider logic in a custom bundle or service.
Email Templates
Override Twig templates for emails (e.g., registration.html.twig) in:
templates/FOSUserBundle/Registration/
Validation Rules
Add constraints to the User entity:
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\NotBlank
* @Assert\Length(min=8)
*/
private $customField;
Bootstrap Assets
The bundle assumes Bootstrap 3 is installed via encore or manually. If missing, add:
yarn add bootstrap@3
Or include manually in base.html.twig.
Locale Support
The bundle inherits FOSUserBundle’s locale settings. Override in config/packages/fos_user.yaml:
fos_user:
locale: pt_BR
Super Admin Role
The fos:user:create --super-admin command grants the ROLE_SUPER_ADMIN role. Ensure your firewall allows it:
access_control:
- { path: ^/admin, roles: ROLE_SUPER_ADMIN }
How can I help you explore Laravel packages today?