I only want to have email as mode of login, I don\'t want to have username. Is it possible with symfony2/symfony3 and FOSUserbundle?
I read here http://groups.google
You can make the username nullable and then remove it from the form type:
First, in AppBundle\Entity\User, add the annotation above the User class
use Doctrine\ORM\Mapping\AttributeOverrides;
use Doctrine\ORM\Mapping\AttributeOverride;
/**
* User
*
* @ORM\Table(name="fos_user")
* @AttributeOverrides({
* @AttributeOverride(name="username",
* column=@ORM\Column(
* name="username",
* type="string",
* length=255,
* unique=false,
* nullable=true
* )
* ),
* @AttributeOverride(name="usernameCanonical",
* column=@ORM\Column(
* name="usernameCanonical",
* type="string",
* length=255,
* unique=false,
* nullable=true
* )
* )
* })
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
*/
class User extends BaseUser
{
//..
When you run php bin/console doctrine:schema:update --force
it will make the username nullable in the database.
Second, in your form type AppBundle\Form\RegistrationType, remove the username from the form.
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->remove('username');
// you can add other fields with ->add('field_name')
}
Now, you won't see the username field in the form (thanks to $builder->remove('username');
). and when you submit the form, you won't get the validation error "Please enter a username" anymore because it's no longer required (thanks to the annotation).
Source: https://github.com/FriendsOfSymfony/FOSUserBundle/issues/982#issuecomment-12931663