tourze / user-id-email-bundle
用户身份电子邮箱管理模块
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/user-id-email-bundle
Requires
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^4.1
- easycorp/easyadmin-bundle: ^4
- knplabs/knp-menu: ^3.7
- symfony/config: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/doctrine-bridge: ^7.3
- symfony/framework-bundle: ^7.3
- symfony/http-kernel: ^7.3
- symfony/property-access: ^7.3
- symfony/security-core: ^7.3
- symfony/yaml: ^7.3
- tourze/bundle-dependency: 1.*
- tourze/doctrine-snowflake-bundle: 1.0.*
- tourze/doctrine-timestamp-bundle: 1.0.*
- tourze/doctrine-user-bundle: 1.0.*
- tourze/easy-admin-menu-bundle: 1.0.*
- tourze/user-id-bundle: 1.0.*
Requires (Dev)
This package is auto-updated.
Last update: 2025-11-13 18:14:39 UTC
README
A Symfony bundle for managing email addresses as user identities with full ORM integration.
Table of Contents
- Features
- Dependencies
- Installation
- Quick Start
- Advanced Usage
- API Reference
- Database Schema
- Security
- License
Features
- Email Identity Management: Store and manage email addresses as user identities
- User Association: Link email identities to Symfony User entities
- Identity Service: Unified service for finding identities by type and user
- Doctrine Integration: Full ORM support with repository pattern
- Timestampable: Automatic creation and update timestamps
- Blameable: Track who created/updated records
- Snowflake ID: Unique identifier generation
- Validation: Built-in email format and length validation
Dependencies
This bundle requires:
- PHP 8.1 or higher
- Symfony 7.3 or higher
- Doctrine ORM 3.0 or higher
- doctrine/dbal ^4.0
Internal dependencies:
- tourze/doctrine-snowflake-bundle
- tourze/doctrine-timestamp-bundle
- tourze/doctrine-user-bundle
- tourze/user-id-bundle
Installation
composer require tourze/user-id-email-bundle
Add the bundle to your config/bundles.php:
return [ // ... Tourze\UserIDEmailBundle\UserIDEmailBundle::class => ['all' => true], ];
Quick Start
Basic Usage
use Tourze\UserIDEmailBundle\Entity\EmailIdentity; use Tourze\UserIDEmailBundle\Service\UserIdentityEmailService; // Create email identity $emailIdentity = new EmailIdentity(); $emailIdentity->setEmailAddress('user@example.com'); $emailIdentity->setUser($user); // Find identity by email $identityService = $container->get(UserIdentityEmailService::class); $identity = $identityService->findByType('email', 'user@example.com'); // Find all identities for a user $identities = $identityService->findByUser($user);
Advanced Usage
Email Validation
The bundle automatically validates email addresses using Symfony's validation constraints:
use Symfony\Component\Validator\Validator\ValidatorInterface; // Validation is automatically applied $emailIdentity = new EmailIdentity(); $emailIdentity->setEmailAddress('invalid-email'); // Will fail validation $violations = $validator->validate($emailIdentity); if (count($violations) > 0) { foreach ($violations as $violation) { echo $violation->getMessage(); } }
Custom Repository Usage
use Tourze\UserIDEmailBundle\Repository\EmailIdentityRepository; // Get repository $repository = $entityManager->getRepository(EmailIdentity::class); // Custom queries $emailIdentities = $repository->findBy([ 'emailAddress' => 'user@example.com' ]); // Find by user $userIdentities = $repository->findBy([ 'user' => $user ]);
Batch Operations
// Create multiple identities $identities = []; foreach ($emailAddresses as $email) { $identity = new EmailIdentity(); $identity->setEmailAddress($email); $identity->setUser($user); $identities[] = $identity; } // Persist all at once foreach ($identities as $identity) { $entityManager->persist($identity); } $entityManager->flush();
API Reference
EmailIdentity Entity
getEmailAddress(): Get the email addresssetEmailAddress(string $emailAddress): Set the email addressgetUser(): Get associated usersetUser(UserInterface $user): Set associated usergetIdentityValue(): Get identity value (email address)getIdentityType(): Get identity type ('email')getIdentityArray(): Get identity as array format
UserIdentityEmailService
findByType(string $type, string $value): Find identity by type and valuefindByUser(UserInterface $user): Find all identities for a user
Database Schema
The bundle creates a table ims_user_identity_email with the following structure:
id: Primary key (Snowflake ID)email_address: Email address (VARCHAR 255)user_id: Foreign key to user tablecreate_time: Creation timestampupdate_time: Last update timestampcreate_user: User who created the recordupdate_user: User who last updated the record
Security
Email Validation
This bundle implements robust email validation to prevent security issues:
- Format Validation: Uses Symfony's
#[Assert\Email]to ensure valid email format - Length Validation: Prevents database overflow with
#[Assert\Length(max: 255)] - SQL Injection Protection: Uses Doctrine ORM parameterized queries
- XSS Prevention: Email addresses are properly escaped when displayed
Data Protection
- User Association: Email identities are always linked to authenticated users
- Audit Trail: All changes are tracked with timestamps and user attribution
- Access Control: Repository methods respect Symfony's security context
Best Practices
- Always validate email addresses before persisting
- Use the service layer instead of direct entity manipulation
- Implement proper authorization checks in your controllers
- Sanitize email inputs in forms and APIs
- Monitor for suspicious patterns in email registration
Reporting Security Issues
If you discover a security vulnerability, please send an email to security@example.com instead of using the issue tracker.
License
This bundle is released under the MIT license. See the LICENSE file for details.