- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 symfony3 中对密码进行编码,但我遇到了一些问题。这是我得到的错误。
Catchable Fatal Error: Argument 3 passed to GMAOBundle\Security\LoginFormAuthentificator::__construct() must be an instance of Symfony\Component\Security\Core\Encoder\UserPasswordEncoder, none given, called in C:\xampp\htdocs\ProjetSomadiag\var\cache\dev\appDevDebugProjectContainer.php on line 483 and defined
我正在与 guard 一起进行身份验证。这是身份验证类名称 loginformauthentificator。
namespace GMAOBundle\Security;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoder;
class LoginFormAuthentificator extends AbstractGuardAuthenticator
{
private $em;
private $router;
private $passwordEncoder;
public function __construct($em, $router,UserPasswordEncoder $PasswordEncoder )
{
$this->em = $em;
$this->router = $router;
//$this->passwordEncoder = new UserPasswordEncoder();
$this->passwordEncoder = $PasswordEncoder;
}
public function getCredentials(Request $request)
{
if ($request->getPathInfo() != '/login' || !$request->isMethod('POST')) {
return;
}
$request->getSession()->set(Security::LAST_USERNAME,$request->request->get('_username'));
return [
'username' => $request->request->get('_username'),
'password' => $request->request->get('_password'),
];
}
public function getUser($credentials, UserProviderInterface $userProvider)
{
$username = $credentials['username'];
return $this->em->getRepository('GMAOBundle:Employe')
->findOneBy(['EmailEmploye' => $username]);
}
/**
* @param mixed $credentials
* @param UserInterface $user
* @return bool
*/
public function checkCredentials($credentials, UserInterface $user)
{
$password=$credentials['password'];
if ($this->passwordEncoder->isPasswordValid($user, $password)) {
return true;
}
return false;
}
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
$request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception);
$url = $this->router->generate('login');
return new RedirectResponse($url);
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
$url = $this->router->generate('gmao_homepage');
return new RedirectResponse($url);
}
public function supportsRememberMe()
{
return true;
}
public function start(Request $request, AuthenticationException $authException = null)
{
$url = $this->router->generate('login');
return new RedirectResponse($url);
}
}
这是用户类。
namespace GMAOBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity
* @ORM\Table(name="employe")
*/
class Employe implements UserInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/private $idEmploye;
/**
* @ORM\Column(type="string")
*/private $NomEmploye;
/**
* @ORM\Column(type="string")
*/private $PrenomEmploye;
/**
* @ORM\Column(type="date", nullable=true)
*/private $DateNaissanceEmploye;
/**
* @ORM\Column(type="string")
*/private $cinEmploye;
/**
* @ORM\Column(type="string", nullable=true)
*/private $AdresseEmploye;
/**
* @ORM\Column(type="string")
*/private $MatriculeEmploye;
/**
* @ORM\Column(type="string", nullable=true)
*/private $SituationFamiliale;
/**
* @ORM\Column(type="string", nullable=true)
*/private $SexeEmploye;
/**
* @ORM\Column(type="string", nullable=true)
*/private $CnssEmploye;
/**
* @ORM\Column(type="string", nullable=true)
*/private $FonctionEmploye;
/**
* @ORM\Column(type="string", nullable=true)
*/private $NumeroMutuelle;
/**
* @ORM\Column(type="date", nullable=true)
*/private $DateDebutEmploye;
/**
* @ORM\Column(type="date", nullable=true)
*/private $DateTitularisationEmploye;
/**
* @ORM\Column(type="string", nullable=true)
*/private $NumeroTelEmploye;
/**
* @ORM\Column(type="string", nullable=true)
*/private $NumeroLigneEmploye;
/**
* @ORM\Column(type="string")
*/private $EmailEmploye;
/**
* A non-persisted field that's used to create the encoded password.
* @var string
*/private $plainPassword;
/**
* @ORM\Column(type="string")
*/private $MdpEmploye;
/**
* @ORM\Column(type="string")
*/private $active;
/**
* @ORM\Column(type="json_array")
*/private $roles = [];
/**
* @ORM\ManyToOne(targetEntity="Departement")
* @ORM\JoinColumn(name="Departement",
referencedColumnName="id_departement")
*/private $Departement;
/**
* @ORM\ManyToOne(targetEntity="Equipe", cascade={"persist"})
* @ORM\JoinColumn(name="Equipe", referencedColumnName="id" ,nullable=true)
*/private $equipe;
/**
* @ORM\Column(type="string", nullable=true)
*/private $imgsrc;
/**
* @ORM\Column(type="string")
*private $responsable_projet;
/**
* @ORM\Column(type="string")
*private $m_GMAO_Projet;
/**
* @ORM\Column(type="string")
*public $m_PMP_Objectif;
/**
* @ORM\Column(type="string")
*public $m_Services;*/
/**
* User Interface Methode Override
*/
function __construct()
{
}
function __destruct()
{
}
public function getUsername()
{
return $this->EmailEmploye;
}
public function getRoles()
{
$roles = $this->roles;
if(!in_array('ROLE_USER',$roles))
{
$roles[]='ROLE_USER';
}
return $roles;
}
public function getPassword()
{
return$this->MdpEmploye;
}
public function getSalt()
{
}
public function eraseCredentials()
{
$this->plainPassword = null;
}
/**
* GETTERS AND SETTERS
**/
/**
* @return mixed
*/
public function getIdEmploye()
{
return $this->idEmploye;
}
/**
* @param mixed $idEmploye
*/
public function setIdEmploye($idEmploye)
{
$this->idEmploye = $idEmploye;
}
/**
* @return mixed
*/
public function getNomEmploye()
{
return $this->NomEmploye;
}
/**
* @param mixed $NomEmploye
*/
public function setNomEmploye($NomEmploye)
{
$this->NomEmploye = $NomEmploye;
}
/**
* @return mixed
*/
public function getPrenomEmploye()
{
return $this->PrenomEmploye;
}
/**
* @param mixed $PrenomEmploye
*/
public function setPrenomEmploye($PrenomEmploye)
{
$this->PrenomEmploye = $PrenomEmploye;
}
/**
* @return mixed
*/
public function getDateNaissanceEmploye()
{
return $this->DateNaissanceEmploye;
}
/**
* @param mixed $DateNaissanceEmploye
*/
public function setDateNaissanceEmploye($DateNaissanceEmploye)
{
$this->DateNaissanceEmploye = $DateNaissanceEmploye;
}
/**
* @return mixed
*/
public function getcinEmploye()
{
return $this->cinEmploye;
}
/**
* @param mixed $cinemploye
*/
public function setcinEmploye($Cinemploye)
{
$this->cinEmploye = $Cinemploye;
}
/**
* @return mixed
*/
public function getAdresseEmploye()
{
return $this->AdresseEmploye;
}
/**
* @param mixed $AdresseEmploye
*/
public function setAdresseEmploye($AdresseEmploye)
{
$this->AdresseEmploye = $AdresseEmploye;
}
/**
* @return mixed
*/
public function getMatriculeEmploye()
{
return $this->MatriculeEmploye;
}
/**
* @param mixed $MatriculeEmploye
*/
public function setMatriculeEmploye($MatriculeEmploye)
{
$this->MatriculeEmploye = $MatriculeEmploye;
}
/**
* @return mixed
*/
public function getSituationFamiliale()
{
return $this->SituationFamiliale;
}
/**
* @param mixed $SituationFamiliale
*/
public function setSituationFamiliale($SituationFamiliale)
{
$this->SituationFamiliale = $SituationFamiliale;
}
/**
* @return mixed
*/
public function getSexeEmploye()
{
return $this->SexeEmploye;
}
/**
* @param mixed $SexeEmploye
*/
public function setSexeEmploye($SexeEmploye)
{
$this->SexeEmploye = $SexeEmploye;
}
/**
* @return mixed
*/
public function getCnssEmploye()
{
return $this->CnssEmploye;
}
/**
* @param mixed $CnssEmploye
*/
public function setCnssEmploye($CnssEmploye)
{
$this->CnssEmploye = $CnssEmploye;
}
/**
* @return mixed
*/
public function getFonctionEmploye()
{
return $this->FonctionEmploye;
}
/**
* @param mixed $FonctionEmploye
*/
public function setFonctionEmploye($FonctionEmploye)
{
$this->FonctionEmploye = $FonctionEmploye;
}
/**
* @return mixed
*/
public function getNumeroMutuelle()
{
return $this->NumeroMutuelle;
}
/**
* @param mixed $NumeroMutuelle
*/
public function setNumeroMutuelle($NumeroMutuelle)
{
$this->NumeroMutuelle = $NumeroMutuelle;
}
/**
* @return mixed
*/
public function getDateDebutEmploye()
{
return $this->DateDebutEmploye;
}
/**
* @param mixed $DateDebutEmploye
*/
public function setDateDebutEmploye($DateDebutEmploye)
{
$this->DateDebutEmploye = $DateDebutEmploye;
}
/**
* @return mixed
*/
public function getDateTitularisationEmploye()
{
return $this->DateTitularisationEmploye;
}
/**
* @param mixed $DateTitularisationEmploye
*/
public function setDateTitularisationEmploye($DateTitularisationEmploye)
{
$this->DateTitularisationEmploye = $DateTitularisationEmploye;
}
/**
* @return mixed
*/
public function getNumeroTelEmploye()
{
return $this->NumeroTelEmploye;
}
/**
* @param mixed $NumeroTelTmploye
*/
public function setNumeroTelEmploye($NumeroTelEmploye)
{
$this->NumeroTelEmploye = $NumeroTelEmploye;
}
/**
* @return mixed
*/
public function getNumeroLigneEmploye()
{
return $this->NumeroLigneEmploye;
}
/**
* @param mixed $NumeroLigneEmploye
*/
public function setNumeroLigneEmploye($NumeroLigneEmploye)
{
$this->NumeroLigneEmploye = $NumeroLigneEmploye;
}
/**
* @return mixed
*/
public function getEmailEmploye()
{
return $this->EmailEmploye;
}
/**
* @param mixed $EmailEmploye
*/
public function setEmailEmploye($EmailEmploye)
{
$this->EmailEmploye = $EmailEmploye;
}
/**
* @return mixed
*/
public function getMdpEmploye()
{
return $this->MdpEmploye;
}
/**
* @param mixed $MdpEmploye
*/
public function setMdpEmploye($MdpEmploye)
{
$this->MdpEmploye = $MdpEmploye;
}
/**
* @return mixed
*/
public function getActive()
{
return $this->active;
}
/**
* @param mixed $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* @return mixed
*/
public function getDepartement()
{
return $this->Departement;
}
/**
* @param mixed $Departement
*/
public function setDepartement($Departement)
{
$this->Departement = $Departement;
}
/**
* @return mixed
*/
public function getImgsrc()
{
return $this->imgsrc;
}
/**
* @param mixed $imgsrc
*/
public function setImgsrc($imgsrc)
{
$this->imgsrc = $imgsrc;
}
public function setRoles($roles)
{
$this->roles =$roles;
}
/**
* @return mixed
*/
public function getEquipe()
{
return $this->equipe;
}
/**
* @param mixed $Equipe
*/
public function setEquipe($Equipe)
{
$this->equipe = $Equipe;
}
/**
* @return string
*/
public function getPlainPassword()
{
return $this->plainPassword;
}
/**
* @param string $plainPassword
*/
public function setPlainPassword($plainPassword)
{
$this->plainPassword = $plainPassword;
$this->password = null;
}
}
我不知道这个错误代表什么。
最佳答案
如果您使用依赖注入(inject),则必须将您的密码编码器作为第三个参数发送。
例子:服务.yml
services:
app.loginform.authenticator:
class: GMAOBundle\Security\LoginFormAuthentificator
arguments:
- "@doctrine.orm.entity_manager"
- "@router"
- "@passwordencoder"
或者您可以“ Autowiring ”。
services:
app.loginform.authenticator:
class: GMAOBundle\Security\LoginFormAuthentificator
autowire: true
或者您正在使用 services.yml 来注入(inject)依赖项。
如果您将 loginFormAuthenticator 创建为对象,则必须将其实例化为:
$loginAuthenticator = new LoginFormAuthentificator($entitymanager, $router, $passwordEncoder);
调用该类时,您在某些参数中缺少密码编码器。
关于php - 使用 symfony3 : Catchable Fatal Error: Argument 3 passed to 编码密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45143899/
我正在使用我的项目this处理ini文件的类。我已经使用 Windows EasyPHP 开发了所有项目,但是当我将它放入我的 Linux 网络服务器时,我总是在日志文件中收到此错误(使用 Light
JSONSerialization.data(withJSONObject:options:)(在 Swift 2 中又称为 dataWithJSONObject)被声明为 throws。但是,传递无
我正在尝试在我的一个类(class)上实现 PHP5 的类型提示, class ClassA { public function method_a (ClassB $b) {} } c
我目前正在为我的在职培训做一个项目。但是我遇到了一个无法解决的错误。 因此,我使用 ManyToOne 关系来连接 2 个事物,即类别中的产品。 但是当我想添加一个产品时,我遇到了这个错误: Cont
当我尝试运行 php artisan (anything) 时出现此错误: PHP Catchable fatal error: Argument 2 passed to Illuminate\Ro
我正在玩 try - catch block : loadHTMLFile($str); $domOb->preserveWhiteSpace = false; $container
我正在尝试在 symfony3 中对密码进行编码,但我遇到了一些问题。这是我得到的错误。 Catchable Fatal Error: Argument 3 passed to GMAOBundle\
为什么我会收到以下信息 error: could not find implicit value for parameter C: scalaz.Catchable[F2]执行P(1,2,3).run
我遇到了一些奇怪的事情: 我通过 app/console doctrine:generate:entity 创建了三个 doctrine 实体: 类别 用户 发布 我建立了关系,并且一切都与 fixt
我运行使用 Zend Framework 2 创建的应用程序时出现此错误: Catchable fatal error: Argument 1 passed to Zend\View\HelperPl
我有以下代码,它从数据库中检索页面 slug,然后需要创建相关的子页面: $builder->add('subtocontentoptions', 'entity', array(
我的 symfony 项目中有这个实体: /** * Batiments * * @ORM\Table(name="batiments") * @ORM\Entity * @ORM\Enti
刚从新项目开始,并想尝试ModX将其用于项目,但是会卡在此错误上(它不会消失): **Catchable fatal error: Argument 2 passed to modParser::co
当我在 Controller 中创建一个表单时,如下所示: $form = $this->createFormBuilder() ->add('field_name') ->getFo
我已经读过 this和 this和其他人,但没有人解决我的问题。 我已经删除了所有可能的内容并将范围缩小到一个字段:地址。当我尝试关注 this tutorial 时,如果我遵循它,一切都会正常,从一
我是一名优秀的程序员,十分优秀!