diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 31761db..50c0427 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -22,14 +22,14 @@ security: entry_point: App\Security\LoginAuthenticator logout: - path: logout - target: login + path: app_logout + target: app_login access_control: # - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } - - { path: ^/logout, roles: IS_AUTHENTICATED_ANONYMOUSLY } +# - { path: ^/logout, roles: ROLE_USER } # - { path: ^/, roles: ROLE_USER } #when@test: diff --git a/src/Controller/LoginController.php b/src/Controller/LoginController.php index f307da5..95d6c71 100644 --- a/src/Controller/LoginController.php +++ b/src/Controller/LoginController.php @@ -12,9 +12,9 @@ class LoginController extends AbstractController #[Route('/login', name: 'app_login')] public function index(AuthenticationUtils $authenticationUtils): Response { -// if ($this->getUser()) { -// return $this->redirectToRoute('index/index.html.twig'); -// } + if ($this->getUser()) { + return $this->redirectToRoute('index/index.html.twig'); + } // get the login error if there is one $error = $authenticationUtils->getLastAuthenticationError(); diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 78490e3..a19eb68 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Entity\Utilisateurs; +use App\Repository\UtilisateursRepository; use App\Form\AddUserFormType; use App\Security\LoginAuthenticator; use Doctrine\ORM\EntityManagerInterface; @@ -15,12 +16,9 @@ use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; class UserController extends AbstractController { - #[Route('/user', name: 'app_user')] - public function index(): Response + public function __construct(UtilisateursRepository $utilisateursRepository) { - return $this->render('user/index.html.twig', [ - 'controller_name' => 'UserController', - ]); + $this->utilisateursRepository = $utilisateursRepository; } #[Route('/user/add', name: 'add_user')] @@ -45,8 +43,18 @@ class UserController extends AbstractController return $security->login($user, LoginAuthenticator::class, 'main'); } - return $this->render('user/user.html.twig', [ + return $this->render('user/add.html.twig', [ 'registrationForm' => $form, ]); } + + #[Route('/user/list', name: 'list_user')] + public function list(): Response + { + $utilisateur = $this->utilisateursRepository->findAll(); + + return $this->render('user/list.html.twig', [ + 'utilisateurs' => $utilisateur + ]); + } } diff --git a/src/Form/AddUserFormType.php b/src/Form/AddUserFormType.php index 31dbe20..c8af47b 100644 --- a/src/Form/AddUserFormType.php +++ b/src/Form/AddUserFormType.php @@ -7,6 +7,7 @@ use App\Entity\Tables; use App\Entity\Clients; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -21,7 +22,7 @@ class AddUserFormType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options): void { $builder - ->add('UserIdentifier') + ->add('UserIdentifier', EmailType::class, ) ->add('Password', PasswordType::class, [ // instead of being set onto the object directly, // this is read and encoded in the controller @@ -29,13 +30,7 @@ class AddUserFormType extends AbstractType 'attr' => ['autocomplete' => 'new-password'], 'constraints' => [ new NotBlank([ - 'message' => 'Please enter a password', - ]), - new Length([ - 'min' => 6, - 'minMessage' => 'Your password should be at least {{ limit }} characters', - // max length allowed by Symfony for security reasons - 'max' => 4096, + 'message' => 'Entrer un mot de passe', ]), ], ]) @@ -43,7 +38,7 @@ class AddUserFormType extends AbstractType ->add('Nom') ->add('Prenom') ->add('Roles', TextType::class) - ->add('Submit', SubmitType::class); + ->add('Enregistrer', SubmitType::class); // Convertir le champ role en tableau diff --git a/templates/login/index.html.twig b/templates/login/index.html.twig index e4c7010..03892a0 100644 --- a/templates/login/index.html.twig +++ b/templates/login/index.html.twig @@ -8,15 +8,6 @@ {% block title %}Login{% endblock %} {% block body %} - {% if error %} -
D:/Devellopement/FestinHegre/src/Controller/UserController.php
D:/Devellopement/FestinHegre/templates/user/index.html.twig
ID | +Nom | +Prenom | +Roles | +|
---|---|---|---|---|
{{ utilisateur.id }} | +{{ utilisateur.nom }} | +{{ utilisateur.prenom }} | +{{ utilisateur.UserIdentifier }} | +{{ utilisateur.roles|join }} | +
Aucun utilisateur trouvé. | +