2

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 :

  1. Creating UserBundle with FOSUserBundle as parent
  2. Add AttributeOverride on username, usernameCanonical, email, and emailCanonical fields.
  3. 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.

Community
  • 1
  • 1
nbonniot
  • 1,034
  • 16
  • 33

1 Answers1

1

I finally found the problem, which was almost as usual between chair and screen.

config.yml BEFORE

registration:
        form:
            type: LCH\UserBundle\Form\RegistrationType

    profile:
        form:
            validation_groups:  [Default] # Here you can also add your own groups if you have extra validation
    registration:
        form:
            validation_groups:  [Default] # Here you can also add your own groups if you have extra validation

The registration.form key was defined twice... After merging them...

profile:
        form:
            validation_groups:  [Default]
    registration:
        form:
            validation_groups:  [Default]
            type: LCH\UserBundle\Form\RegistrationType

...Everything rocks.

nbonniot
  • 1,034
  • 16
  • 33
  • Perfect! I had the same situation and this solution works like a charm for me too!! – Ren Jan 31 '18 at 16:00