c975l/user-bundle
GDPR-focused user management bundle inspired by FOSUserBundle: Doctrine entities (extendable), signup/signin/profile/password reset forms, email notifications, social login (HWIOAuth), public profiles, anti-brute-force delays, Gravatar/social avatars, JS data access, and JSON API.
Installation
composer require c975l/user-bundle
Ensure v3.x for Symfony 4.x or v2.x for Symfony 3.x.
Configure Security
Update config/packages/security.yml to specify your chosen User entity (e.g., User, UserAddress, UserBusiness) and define role hierarchies:
security:
encoders:
c975L\UserBundle\Entity\User: auto
providers:
c975_l_userbundle:
entity:
class: c975L\UserBundle\Entity\User
Database Setup
Run the SQL script from /Resources/sql/user.sql to create user and user_archives tables.
Enable Routes
Add to config/routes.yaml:
c975_l_user:
resource: "@c975LUserBundle/Controller/"
type: annotation
prefix: /
Install Assets
php bin/console assets:install --symlink
First Use Case
Access /user_signup to test the registration flow. Override templates in /templates/bundles/c975LUserBundle/ (e.g., layout.html.twig) to customize the UI.
User Management
UserSignupType to add custom fields (e.g., src/App/Form/UserSignupType).UserProfileType to modify editable fields (e.g., disable fields during signup)./user_reset_password route; customize the email template via c975LEmailBundle.GDPR Compliance
/user_export to provide users with their data in JSON/CSV.allow_use flag (set to false in UserAbstract).Social Logins
HWIOAuthBundle (e.g., Facebook/Google) and enable in config_bundles.yaml:
c975LUser:
hwiOauth: ['facebook', 'google']
social: true
routes.yaml and register OAuthUserProvider in services.yaml.API Integration
Use the built-in API endpoints (e.g., /api/user) for JSON-based CRUD operations. Authenticate via JWT (configure lcobucci/jwt).
Event-Driven Extensions
Subscribe to events (e.g., UserEvent::USER_DELETE) to trigger custom logic:
// src/EventListener/UserDeleteListener.php
public static function getSubscribedEvents() {
return [UserEvent::USER_DELETE => 'onUserDelete'];
}
user_divData() to pass user data to JavaScript or user_avatar() for profile pictures.business_siret).UserFull entity or override templates with _locale routing.security.yml:
firewalls:
main:
form_login:
check_path: user_signin
failure_path: user_signin_failure
Entity Selection
security.yml class matches your extended entity (e.g., App\Entity\User).UserAbstract, ensure all required fields (e.g., email, roles) are preserved.Template Overrides
/templates/bundles/c975LUserBundle/ to avoid Symfony’s cache issues.navbarMenuActions.html.twig if extending the navbar without full template duplication.Social Login Quirks
parameters.yml).social_token) are stored in the UserSocial entity but require manual HWIOAuth setup.API Limitations
lcobucci/jwt is installed and configured for API auth.GDPR Edge Cases
sp_UserArchive() stored procedure to archive user data before deletion.php bin/console cache:clear) after adding routes or services.UserProfileType/UserSignupType for field constraints (e.g., business_siret requires validation).$event->stopPropagation() in listeners to halt default behavior (e.g., during deletion).Custom Fields
Extend UserAbstract and update UserProfileType:
// src/App/Entity/CustomUser.php
class CustomUser extends UserAbstract {
private $customField;
// Add getter/setter + validation.
}
Email Templates
Override c975LEmailBundle templates (e.g., reset_password.html.twig) in /templates/bundles/c975LEmailBundle/.
Dashboard Actions
Modify dashboardActions.html.twig to add custom buttons (e.g., "Upload Documents").
Validation Rules Add constraints to extended entities:
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\Length(min=14, max=14)
*/
private $business_siret;
API Extensions
Create custom controllers extending c975L\UserBundle\Controller\ApiController for additional endpoints.
c975LEmailBundle config:
c975_l_email:
save_emails: false
config.yml:
c975_l_user:
public_profile: false
_locale routing and override UserFull fields (e.g., firstname_en, firstname_fr).user_avatar() with cached sizes (e.g., user_avatar(128)) to avoid repeated image processing.email and identifier fields in user.sql for large-scale apps.
How can I help you explore Laravel packages today?