Когда я хочу соединиться с моим идентификатором и паролем, у меня появляется ошибка «Неверные учетные данные» в моем флеш-сообщении.Я не понимаю, почему это не работает
У меня есть 2 пользователя в моей БД с тем же паролем Toto и тест
Моя ошибка:
Мой SecurityController:
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\Operateur;
class SecurityController extends AbstractController
{
/**
* @Route("/connexion", name="connexion")
*/
public function connexion(Request $request ,AuthenticationUtils $authUtils)
{
$error = $authUtils->getLastAuthenticationError();
$lastUsername = $authUtils->getLastUsername();
return $this->render('security/connexion.html.twig', array(
'last_username' => $lastUsername,
'error' => $error,
));
}
}
мой security.yaml (я думал, что это был кодер, который я снял, но ничего не делает)
security:
#Permet d'encrypter le mot de passe par l'utilisateur au moment de la saisie
encoders:
App\Entity\Operateur:
algorithm: bcrypt
#Permet de définir où les opérateurs sont stockés pour l'autentification
providers:
badgeuse_db:
entity:
class: App\Entity\Operateur
property: prenom
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
provider: badgeuse_db
pattern: ^/
form_login:
login_path: connexion
check_path: connexion
logout:
path: /deconnexion
target: /
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
#- { path: /profile, roles: ROLE_USER }
Моя веточка:
{% extends 'base.html.twig' %}
{% block body %}
{% if error %}
<div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
<form class="form-connexion" action="{{ path('connexion') }}" method="post">
<div class="form-group">
<label for="username">Prénom</label>
<input type="text" class="form-control" id="username" name="_username" placeholder="Entrez votre prénom" value="{{ last_username }}">
</div>
<div class="form-group">
<label for="password">Mot de passe</label>
<input type="password" class="form-control" id="password" name="_password" placeholder="Entrez votre mot de passe">
</div>
<button type="submit" value="Connexion" class="btn btn-primary">Connexion</button>
</form>
{% endblock %}
Моя сущность:
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass="App\Repository\OperateurRepository")
*/
class Operateur implements UserInterface , \Serializable
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=120)
*/
private $nom;
/**
* @ORM\Column(type="string", length=120)
*/
private $prenom;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $utilisateur_windows;
/**
* @ORM\Column(type="string", length=255)
*/
private $code_operateur;
/**
* @ORM\OneToMany(targetEntity="App\Entity\HistoOperateur", mappedBy="operateur")
*/
private $histoOperateurs;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Role", mappedBy="operateur")
*/
private $role;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Nationalite", mappedBy="operateur")
*/
private $nationalites;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Societe", mappedBy="operateur")
*/
private $societes;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Email", mappedBy="operateur")
*/
private $emails;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\TempsPasse", inversedBy="operateurs")
*/
private $temps_passes;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Conges", mappedBy="operateurs")
*/
private $conges;
/**
* @ORM\Column(type="string", length=255)
*/
private $mot_de_passe;
public function __construct()
{
$this->histoOperateurs = new ArrayCollection();
$this->role = new ArrayCollection();
$this->nationalites = new ArrayCollection();
$this->societes = new ArrayCollection();
$this->emails = new ArrayCollection();
$this->temps_passes = new ArrayCollection();
$this->conges = new ArrayCollection();
}
public function getRoles()
{
return ['ROLE_USER'];
}
public function getUsername()
{
return $this->username;
}
public function getPassword()
{
}
public function getSalt()
{
}
public function eraseCredentials()
{
}
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getMotDePasse(): ?string
{
return $this->mot_de_passe;
}
public function setMotDePasse(string $mot_de_passe): self
{
$this->mot_de_passe = $mot_de_passe;
return $this;
}
public function getPrenom(): ?string
{
return $this->prenom;
}
public function setPrenom(string $prenom): self
{
$this->prenom = $prenom;
return $this;
}
public function getUtilisateurWindows(): ?string
{
return $this->utilisateur_windows;
}
public function setUtilisateurWindows(?string $utilisateur_windows): self
{
$this->utilisateur_windows = $utilisateur_windows;
return $this;
}
public function getCodeOperateur(): ?string
{
return $this->code_operateur;
}
public function setCodeOperateur(string $code_operateur): self
{
$this->code_operateur = $code_operateur;
return $this;
}
/**
* @return Collection|HistoOperateur[]
*/
public function getHistoOperateurs(): Collection
{
return $this->histoOperateurs;
}
public function addHistoOperateur(HistoOperateur $histoOperateur): self
{
if (!$this->histoOperateurs->contains($histoOperateur)) {
$this->histoOperateurs[] = $histoOperateur;
$histoOperateur->setOperateur($this);
}
return $this;
}
public function removeHistoOperateur(HistoOperateur $histoOperateur): self
{
if ($this->histoOperateurs->contains($histoOperateur)) {
$this->histoOperateurs->removeElement($histoOperateur);
// set the owning side to null (unless already changed)
if ($histoOperateur->getOperateur() === $this) {
$histoOperateur->setOperateur(null);
}
}
return $this;
}
/**
* @return Collection|Role[]
*/
public function getRole(): Collection
{
return $this->role;
}
public function addRole(Role $role): self
{
if (!$this->role->contains($role)) {
$this->role[] = $role;
$role->setOperateur($this);
}
return $this;
}
public function removeRole(Role $role): self
{
if ($this->role->contains($role)) {
$this->role->removeElement($role);
// set the owning side to null (unless already changed)
if ($role->getOperateur() === $this) {
$role->setOperateur(null);
}
}
return $this;
}
/**
* @return Collection|Nationalite[]
*/
public function getNationalites(): Collection
{
return $this->nationalites;
}
public function addNationalite(Nationalite $nationalite): self
{
if (!$this->nationalites->contains($nationalite)) {
$this->nationalites[] = $nationalite;
$nationalite->setOperateur($this);
}
return $this;
}
public function removeNationalite(Nationalite $nationalite): self
{
if ($this->nationalites->contains($nationalite)) {
$this->nationalites->removeElement($nationalite);
// set the owning side to null (unless already changed)
if ($nationalite->getOperateur() === $this) {
$nationalite->setOperateur(null);
}
}
return $this;
}
/**
* @return Collection|Societe[]
*/
public function getSocietes(): Collection
{
return $this->societes;
}
public function addSociete(Societe $societe): self
{
if (!$this->societes->contains($societe)) {
$this->societes[] = $societe;
$societe->setOperateur($this);
}
return $this;
}
public function removeSociete(Societe $societe): self
{
if ($this->societes->contains($societe)) {
$this->societes->removeElement($societe);
// set the owning side to null (unless already changed)
if ($societe->getOperateur() === $this) {
$societe->setOperateur(null);
}
}
return $this;
}
/**
* @return Collection|Email[]
*/
public function getEmails(): Collection
{
return $this->emails;
}
public function addEmail(Email $email): self
{
if (!$this->emails->contains($email)) {
$this->emails[] = $email;
$email->setOperateur($this);
}
return $this;
}
public function removeEmail(Email $email): self
{
if ($this->emails->contains($email)) {
$this->emails->removeElement($email);
// set the owning side to null (unless already changed)
if ($email->getOperateur() === $this) {
$email->setOperateur(null);
}
}
return $this;
}
/**
* @return Collection|TempsPasse[]
*/
public function getTempsPasses(): Collection
{
return $this->temps_passes;
}
public function addTempsPass(TempsPasse $tempsPass): self
{
if (!$this->temps_passes->contains($tempsPass)) {
$this->temps_passes[] = $tempsPass;
}
return $this;
}
public function removeTempsPass(TempsPasse $tempsPass): self
{
if ($this->temps_passes->contains($tempsPass)) {
$this->temps_passes->removeElement($tempsPass);
}
return $this;
}
public function __toString()
{
return $this->nom;
}
/**
* @return Collection|Conges[]
*/
public function getConges(): Collection
{
return $this->conges;
}
public function addConge(Conges $conge): self
{
if (!$this->conges->contains($conge)) {
$this->conges[] = $conge;
$conge->addOperateur($this);
}
return $this;
}
public function removeConge(Conges $conge): self
{
if ($this->conges->contains($conge)) {
$this->conges->removeElement($conge);
$conge->removeOperateur($this);
}
return $this;
}
//encode et decode l'objet user en session
/** @see \Serializable::serialize() */
public function serialize()
{
return serialize(array(
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt,
));
}
/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
list(
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized, array('allowed_classes' => false));
}
}