0
votes

i am using fosuserbundle to login users and this is working fine.

But for a new project i want a 3 field login like this :

Field Companyname

Field Username

Field Password

My question is how to add extra field to authenticate users ?

Example of my security.yml

security: encoders: FOS\UserBundle\Model\UserInterface: sha512

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

providers:
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
        logout:       true
        anonymous:    true

access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/, role: ROLE_ADMIN }

And here is a example of my User entity class. (User.php)

<?php
// src/Acme/UserBundle/Entity/User.php

namespace TommieCrawford\UserBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
}

Anyone that know's how to do this ?! Maybe some samples?

Many thanks!

1

1 Answers

1
votes

They have this process documented. Go here

https://github.com/FriendsOfSymfony/FOSUserBundle/tree/master/Resources/doc

And read through the overriding_*.md documents. If you get stuck, come back here.