php Symfony中不支持的方法

9rygscc1  于 2023-02-03  发布在  PHP
关注(0)|答案(1)|浏览(195)

我在我的symfony项目2Fa认证的帮助下实现的官方文档。一切都很好,直到我尝试定制的条件,使用户被迫通过2Fa的形式,使用文档method
当我在函数shouldPerformTwoFactorAuthentication中开始实现代码时,问题就开始了,就好像它是一个普通函数一样,我尝试这样做:

public function shouldPerformTwoFactorAuthentication(AuthenticationContextInterface $context, ManagerRegistry $doctrine, UserInterface $userInterface): bool
    {
        $entityManager = $doctrine->getManager();
        $user = $entityManager->getRepository(User::class)->findOneBy(['email' => $userInterface->getUserIdentifier()]);
        if ($user->isIsGoogleEnabled()) {
            return false;
        } else {
            return false;
        }
    }

正如你所看到的,我试图自定义什么时候让它工作,什么时候不工作,但我得到这个错误:
Method 'App\Controller\TwoFactorConditionController::shouldPerformTwoFactorAuthentication()' is not compatible with method 'Scheb\TwoFactorBundle\Security\TwoFactor\Condition\TwoFactorConditionInterface::shouldPerformTwoFactorAuthentication()'.intelephense(1038)
我一直在互联网上搜索,没有结果,为我工作,直到我发现this
我已经做了这么多的尝试,我不会张贴他们,如果有人可以指导我,我感谢你的时间,谢谢!

uoifb46i

uoifb46i1#

这将使用__construct()方法工作

private EntityManagerInterface $entityManager;
private UserInterface $userInterface;

public function __construct(EntityManagerInterface $entityManager, UserInterface $userInterface)
{
  $this->entityManager = $entityManager;
  $this->userInterface = $userInterface;
}

public function shouldPerformTwoFactorAuthentication(AuthenticationContextInterface $context): bool
{        
  $user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $this->userInterface->getUserIdentifier()]);
  if ($user->isIsGoogleEnabled()) {
    return false;
  } else {
    return false;
  }
}

相关问题