php - Why can't I block a user in Symfony 6?

one text

Im using symfony 6 and easyadmin 4. I'm trying to figure out how to block a user account on my website but I can't find a solution. I tried to:

  1. Store users status in a boolean column (able to connect or not)
  public function isIsEnabled(): ?bool
    {
        return $this->isEnabled;
    }

    public function setIsEnabled(bool $isEnabled): self
    {
        $this->isEnabled = $isEnabled;

        return $this;
    }

  1. Prevent the user from logging in in SecureController
    public function login(AuthenticationUtils $authenticationUtils): Response
    {
        // if ($this->getUser()) {
        //     return $this->redirectToRoute('target_path');
        // }
        $user = new User();
        if (!$user->isIsEnabled()) {
            // fail authentication with a custom error
            throw new CustomUserMessageAuthenticationException('Account is disabled.');
        }
        
        // get the login error if there is one
        $error = $authenticationUtils->getLastAuthenticationError();
        // last username entered by the user
        $lastUsername = $authenticationUtils->getLastUsername();

        return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
    }

    #[Route(path: '/logout', name: 'app_logout')]
    public function logout(): void
    {
        throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
    }
}
  1. Be able to disable a user with EasyAdmin by using a boolean field

But yet the User can still connect and I don't know why? I think it's the $user = new User(); line but I don't know how to use the isIsEnabled() method in another file without using the User entity. Can someone help, please? thanks in advance.

Source