Logowanie Symfony 4

0

Witam.Mam taki problem ,otóż chciałbym aby dany użytkownik mógł się zalogować na stronie,dodam ,ze mam już formularz logowania i rejestracji(mogę dodawać nowych użytkowników do bazy i ich zapisać ),ale nie bardzo wiem jak to zrobić ,ma troche kodu ale nie wiem czy to jest dobrze gdyż mam bład:Field 'login' not found in \Symfony\Component\Form\FormInterface

if ($form->isSubmitted() && $form->isValid())
        {
            $User=$this->getDoctrine()->getRepository(Users::class)->findOneBy($form->users);
            if($User->getLogin()==$form->login&&$User->getPassword()==$form->password)
            {
                $session=new Session();
                $session->start();
                $session->set("klient",$User);
                return $this->redirectToRoute('main');
            }
            else return $this->redirectToRoute('signin_add',array("message"=>'Błędny login lub hasło'));
        }

nie wiem co mam wpisać w miejsce findOneBy($form->users);, if($User->getLogin()==$form->login&&$User->getPassword()==$form->password)

0

dobrze bo już posiadam formularz :
use App\Entity\Users;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class SignInController extends AbstractController
{
/**
* @Route("SignIn", name="signin_add")
*
* @return Response
*/

public function SignIn(Request $request)
{
    $user = new Users();


    $form = $this->createFormBuilder($user)
        ->add("Login",TextType::class)
        ->add("Password",PasswordType::class)
        ->add("Submit",SubmitType::class, array('label' => 'Zaloguj się'))
        ->getForm();

    return $this->render("Form/signin.html.twig", array('form' => $form->createView(),));
}

}```

0

Nie, to masz źle, sf4 ma to tak zrobione, że nie musisz dodawać form. Usuń metode i daj to

    /**
     * @Route("/login", name="app_login")
     */
    public function login(AuthenticationUtils $authenticationUtils): Response
    {
        // 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
        ]);
    }

1 użytkowników online, w tym zalogowanych: 0, gości: 1