everyone and thank you for your future help
I am creating a blog and I want to put the login and registration page on the same view and for that I did all my treatment in login method
and return in the same view the 2 forms registration and connection
I already tried to make a render but it does not work and I even removed the token button no works
public function login(AuthenticationUtils $authenticationUtils, Request $request, UserPasswordEncoderInterface $passwordEncoder, MailerService $mailerService, \Swift_Mailer $mailer): Response
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
$user = new User();
$form = $this->createForm(RegistrationFormType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// encode the plain password
$user->setPassword(
$passwordEncoder->encodePassword(
$user,
$form->get('password')->getData()
)
);
$user->setConfirmationToken($this->generateToken());
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($user);
$entityManager->flush();
$token = $user->getConfirmationToken();
$email = $user->getEmail();
$username = $user->getUsername();
$mailerService->sendToken($mailer, $token, $email, $username, 'registration.html.twig');
return $this->redirectToRoute('app_login');
}
return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error, 'registrationForm' => $form->createView()]);
}
template :
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="section-row">
<div class="section-title">
<h1 class="title text-center">Connexion</h1>
</div>
{% if error %}
<div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
<form method="post">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<input class="input" value="{{ last_username }}" type="text" name="username" placeholder="Nom d'utilisateur">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<input class="input" type="password" name="password" placeholder="Mot de passe">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label>
<input type="checkbox" name="_remember_me"> Se souvenir de moi
</label>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<a href="{{ path('forgotten_password') }}">Mot de passe oublier</a>
</div>
</div>
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
<div class="col-md-12">
<button class="primary-button" type="submit">
Se connecter
</button>
</div>
</div>
</form>
</div>
</div>
<div class="col-md-6">
<h1>Register</h1>
{{ form_start(registrationForm) }}
{{ form_row(registrationForm.username) }}
{{ form_row(registrationForm.password.first) }}
{{ form_row(registrationForm.password.second) }}
<button class="btn">Register</button>
{{ form_end(registrationForm) }}
</div>
</div>
</div>
the problem when I want to register it does not work it sends me back that the token is invalid while for this connect it works properly Thanks you for you help my friends !