Bonjour,
Voila je rencontre un petit problème avec mon code.
jai crée un formaulaire d'inscription en ligne dans lequel l'utilisateur saisie tous les champs.
Ensuite jai creer une page login dans laquelle l'utilisateur renseigne son email et son mot de passe.
Tout se passe bien lorsque l'utilisateur saisie ses identifiants de connexion. Voici mon controller qui permet de soumettre le formulaire et gerer le login user.
Mon fichier SecurityController.php
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\User;
use App\Form\RegistrationType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class SecurityController extends AbstractController
{
/**
* @Route("/inscription_en_ligne", name="security_registration")
*/
public function Registration(Request $request, ObjectManager $manager, UserPasswordEncoderInterface $encoder)
{
$user = new User();
$form = $this->createForm(RegistrationType::class , $user);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
$hash = $encoder->encodePassword($user, $user->getPassword());
$user->setPassword($hash);
$manager->persist($user);
$manager->flush();
$this->addFlash(
'notice',
'VOTRE INSCRIPTION A ÉTÉ ENREGISTRÉE !!!'
);
// return $this->redirectToRoute('page');
}
return $this->render('page/inscription_en_ligne.html.twig',[
'form' => $form->createView()
]);
}
/**
* @Route("/espace_eleve/{id}", name="user_show")
*/
public function show($id) {
$user = $this->getDoctrine()->getRepository(User::class)->find($id);
return $this->render('page/espace_eleve.html.twig', array('user' => $user));
}
/**
* @Route("/user/delete/{id}")
* @Method({"DELETE"})
*/
/*
public function delete(Request $request, $id, ObjectManager $manager) {
$user = $this->getDoctrine()->getRepository(User::class)->find($id);
$manager = $this->getDoctrine()->getManager();
$manager->remove($user);
$manager->flush();
$response = new Response();
$response->send();
}
*/
/**
* @Route("user/edit/{id}", name="edit_form")
* Method({"GET", "POST"})
*/
public function edit(Request $request, ObjectManager $manager) {
$user = new User();
$form = $this->createForm(RegistrationType::class , $user);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
$manager->flush();
// return $this->redirectToRoute('article_list');
}
return $this->render('page/modifier.html.twig',[
// 'id' => $id,
'form' => $form->createView()
]);
}
/**
* @Route("/connexion", name="security_login")
*/
public function security_login(Request $request, AuthenticationUtils $authenticationUtils){
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
// var_dump($lastUsername);
// die();
return $this->render("security/login.html.twig",[
'last_username' => $lastUsername,
'error'=> $error,
]);
}
/**
* @Route("/deconnexion", name="security_logout")
*/
public function logout(){
}
}
Mon ficheir IndexController.php
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
class IndexController extends AbstractController
{
/**
* @Route("/index", name="index")
*/
public function index()
{
return $this->render('page/index.html.twig', [
"page" => "home",
"title" => "home",
]);
}
public function page($page, Request $request)
{
$pageArray = [
"modifier",
"cours",
"enseignant",
"ecole",
"contact",
"presentation",
"equipe_pedagogique",
"activites_pedagogiques",
"charte_parent_accompagnateurs",
"projet_educatif",
"bibliotheque",
"salle_multimedia",
"infirmerie",
"car_de_transport",
"menus_cantine",
"vacances_scolaires",
"reglement_interieur",
"identification",
"connexion",
"historique",
"inscription_en_ligne",
"processus",
"espace_eleve",
'login',
];
if(!in_array($page, $pageArray)){
return $this->redirectToroute("index");
}
return $this->render("page/$page.html.twig", [
"page" => $page,
"title" => ucfirst($page),
]);
}
}
Mon fichier routes.yaml
index:
path: /
controller: App\Controller\IndexController::index
page:
path: /{page}
controller: App\Controller\IndexController::page
#login:
# path: /{page}/{id}
#controller: App\controller\SecurityController::show
Mon fichier security.yaml
security:
encoders:
App\Entity\User:
algorithm: bcrypt
providers:
in_database:
entity:
class: App\Entity\User
property: code_paiement
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
form_login:
login_path: security_login
check_path: security_login
#default_target_path: /espace_eleve/{id}
always_use_default_target_path: false
provider: in_database
logout:
path: security_logout
target: security_registration
# activate different ways to authenticate
#default_target_path: /page
#always_use_default_target_path: true
# http_basic: true
# https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
# form_login: true
# https://symfony.com/doc/current/security/form_login_setup.html
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
Je veux afficher les details du formulaire lorsque l'utilisateur saisie ses identifiants de connexion. afin qu'il voie les details de ce qu'il a saisie dans le formaulire d'inscription dans sa session. Je ne sais comment definir la route qui vas me permettre une fois l'utiliasteur connecter de lui ramener les details du formulaire.
Merci de me repondre SVP