I built a multisite app, with following requirements : user should be able to create accounts on differents sites of the collection, with same email and username.
Here is what I did :
- Creating UserBundle with FOSUserBundle as parent
- Add AttributeOverride on username, usernameCanonical, email, and emailCanonical fields.
- Disable initial validation groups (registration and profile) by overriding validation groups.
Point 2:
/**
* User
* The user class to work with, based on FOSUser one.
* To improve loose coupling, don't forget to link FOS\UserBundle\Model\UserInterface instead.
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="LCH\UserBundle\Entity\UserRepository")
*
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(
* name="email",
* column=@ORM\Column(
* type="string",
* name="email",
* length=255,
* nullable=false,
* unique=false
* )
* ),
* @ORM\AttributeOverride(
* name="emailCanonical",
* column=@ORM\Column(
* type="string",
* name="email_canonical",
* length=255,
* nullable=false,
* unique=false
* )
* ),
* @ORM\AttributeOverride(
* name="username",
* column=@ORM\Column(
* type="string",
* name="username",
* length=255,
* nullable=false,
* unique=false
* )
* ),
* @ORM\AttributeOverride(
* name="usernameCanonical",
* column=@ORM\Column(
* type="string",
* name="username_canonical",
* length=255,
* nullable=false,
* unique=false
* )
* )
* })
*/
Point 3
fos_user:
profile:
form:
validation_groups: [Default]
registration:
form:
validation_groups: [Default]
Last 2 points achieved thanks to this question.
But on form validation, I still have error triggered telling me that email address is already used.
My last attempt was trying to override vendor/friendsofsymfony/user-bundle/Resources/config/storage-validation/orm.xml, (where unique constraint lies) by redefining it in my child bundle. It didn't work either, and this was just a "desperate" try, because if it turned out working, I wouldn't have understood why using preceeding points.