Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email user not required

I would like set email to not required on my User entities. How do what ? I've searched in FOSUserBundle/config/ but i don't find any "required" parameter about email.

like image 862
bux Avatar asked Oct 07 '22 16:10

bux


1 Answers

Following Tib's answer, here is the way I did it. It's working fine :

/**
 * User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity
 * @ORM\AttributeOverrides({
 *      @ORM\AttributeOverride(name="email", column=@ORM\Column(type="string", name="email", length=255, unique=false, nullable=true)),
 *      @ORM\AttributeOverride(name="emailCanonical", column=@ORM\Column(type="string", name="email_canonical", length=255, unique=false, nullable=true))
 * })
 */
class User extends BaseUser {
    // ...
}

EDIT :

The previous solution is easy to implement and was working fine, but after updating Symfony to version 2.1.8 and without changing anything in my app, generating entities failes throwing a Doctrine mapping exception (Invalid field override ...)

In spite of loosing a lot of time trying to solve that issue, I was just stucked.

Then I finally realized that FOSUserBundle provides lot of features I don't use, but doesn't really fit my needs, which are quite basic.

I need to disable email requirement because my app user management is "software like" : no registration, no email sending, no profil, user and roles managed only by admin, etc...

I was adapting a tool not designed for my needs. So I decided to make my own implementation of Symfony security.

It is a little more work, but it's not very difficult and the result is far better and more flexible than adapting FOSUserBundle. Of course, for a "classic" website or web app, FOSUserBundle is the best.

If you are in this case too, I suggest you to do so. Here is the doc to begin : Security in the Book and Security in the CookBook

I hope this can help you.

Sorry for my poor english, I hope it is intelligible

like image 100
bgaze Avatar answered Oct 11 '22 04:10

bgaze