After authentication , when I enter the right username/password I'm redirected to a new page ( driverspace/dashboard ) with this error :
You cannot refresh a user from the EntityUserProvider that does not contain an identifier.
The user object has to be serialized with its own identifier mapped by Doctrine.
And the symfony bar shows : "You are not authenticated" ..
Here my security.xml firewalls:
driver_firewall:
pattern: ^/driver
form_login:
provider: user_db
login_path: /driver/login
check_path: /driver/login_check
remember_me: true
always_use_default_target_path: false
default_target_path: /driverspace/dashboard
target_path_parameter: _target_path
use_referer: false
logout:
path: /driver/logout
target: /
remember_me:
key: MiPassphrase
lifetime: 1800
path: /.*
domain: ~
security: true
anonymous: true
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
PS : I have 2 Type of user , so i worked with fos to manage one and the basic authentication to manage the other , EDIT : Driver ENTITY
class Driver extends BaseUser implements \FOS\UserBundle\Model\UserInterface
{
/**
* @var integer
*
* @ORM\Column(name="id_driver", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $idDriver;
/**
* @var string
*
* @ORM\Column(name="fname_drive", type="string", length=30, nullable=false)
*/
private $fnameDrive;
/**
* @var string
*
* @ORM\Column(name="lname_driver", type="string", length=30, nullable=false)
*/
private $lnameDriver;
/**
* @var string
*
* @ORM\Column(name="phone_driver", type="string", length=15, nullable=false)
*/
private $phoneDriver;
/**
* @var float
*
* @ORM\Column(name="lat_driver", type="float", precision=10, scale=0, nullable=true)
*/
private $latDriver;
/**
* @var float
*
* @ORM\Column(name="lon_driver", type="float", precision=10, scale=0, nullable=true)
*/
private $lonDriver;
/**
* @var integer
*
* @ORM\Column(name="activenow", type="integer", nullable=true)
*/
private $activenow;
/**
* @var \Company
*
* @ORM\ManyToOne(targetEntity="Company")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="company_id", referencedColumnName="id_company")
* })
*/
private $company;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Car", inversedBy="idDriver")
* @ORM\JoinTable(name="driver_car",
* joinColumns={
* @ORM\JoinColumn(name="id_driver", referencedColumnName="id_driver")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="id_car", referencedColumnName="id_car")
* }
* )
*/
private $idCar;
I solved the problem by :
1- Changing idDriver to id , because the driver class extends BaseUSer
2- adding :
public function serialize() {
return serialize($this->id);
}
public function unserialize($data) {
$this->id = unserialize($data);
}
I hope this solution will help someone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With