I do have a problem with my symfony code, I'm actually searching how to put two forms, one for connections and one for login on the same page and this shows me error if I submit the register form, because it is the specified page in security.yaml : here is the code for my register form...
class SecurityController extends AbstractController
{
/**
* @Route("/", name="register_login")
*/
public function register(UserPasswordEncoderInterface $hasher,
Request $request, ObjectManager $manager)
{
$userInfos = new UserInfos();
$form = $this->createForm(RegistrationType::class, $userInfos);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid())
{
$userInfos->setLastConnection(new \DateTime());
$userInfos->setSubscribedAt(new \DateTime());
$userInfos->setPassword($hasher->encodePassword($userInfos,
$userInfos->getPassword()));
$manager->persist($userInfos);
$manager->flush();
}
return $this->render('security/login.html.twig', [
'formUser' => $form->createView()
]);
}
}
and it returns the twig file with the login form...
<form class="form-inline my-2 my-lg-0" action="{{ path('register_login') }}" method="post">
<input class="form-control mr-sm-2" required type="email" name="_username" placeholder="Email">
<input class="form-control mr-sm-2" required type="password" name="_password" placeholder="Mot de passe">
<button class="btn btn-success my-2 my-sm-0" type="submit">Connexion</button>
</form>
My security.yaml config: security: encoders: App\Entity\UserInfos: algorithm: bcrypt
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
in_memory: { memory: ~ }
DB:
entity:
class: App\Entity\UserInfos
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: true
provider: DB
form_login:
login_path: register_login
check_path: register_login
Thanks for your attention.