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 %} -
{{ error.messageKey|trans(error.messageData, 'security') }}
- {% endif %} - - {% if app.user %} -
- You are logged in as {{ app.user.userIdentifier }}, Logout -
- {% endif %} - -
-
- -
-
- {{ form_start(form) }} -

Bienvenue !

-
- {{ form_label(form.email) }} - {{ form_widget(form.email, {'attr': {'class': 'form-control'}}) }} -
-
- {{ form_label(form.password) }} - {{ form_widget(form.password, {'attr': {'class': 'form-control'}}) }} -
-
- {{ form_widget(form.confirm, {'attr': {'class': 'btn btn-primary'}}) }} -
- {{ form_end(form) }} -
-
-

Volaille en fête, Saveurs parfaites !

-
-
-{% endblock %} diff --git a/templates/user/add.html.twig b/templates/user/add.html.twig new file mode 100644 index 0000000..b13bd8c --- /dev/null +++ b/templates/user/add.html.twig @@ -0,0 +1,105 @@ +{% extends 'base.html.twig' %} + +{% block stylesheets %} + +{% endblock %} + +{% block title %}Nouvelle Utilisateur{% endblock %} + +{% block body %} +
+

Nouvelle Utilisateur ! ✅

+ + {{ form_start(registrationForm) }} + {{ form_errors(registrationForm) }} + +
+ {{ form_row(registrationForm.Nom, {'attr': {'class': 'form-input'}, 'label': 'Nom'}) }} +
+
+ {{ form_row(registrationForm.Prenom, {'attr': {'class': 'form-input'}, 'label': 'Prénom'}) }} +
+
+ {{ form_row(registrationForm.UserIdentifier, {'attr': {'class': 'form-input'}, 'label': 'Email'}) }} +
+
+ {{ form_row(registrationForm.Password, {'attr': {'class': 'form-input'}, 'label': 'Password'}) }} +
+
+ {{ form_row(registrationForm.Roles, {'attr': {'class': 'form-input'}, 'label': 'Roles'}) }} +
+
+ {{ form_row(registrationForm.Enregistrer, {'attr': {'class': 'btn-save'}, 'label': 'Enregistrer'}) }} +
+ + {{ form_end(registrationForm) }} + +
+ Liste des Utilisateur +
+
+{% endblock %} diff --git a/templates/user/index.html.twig b/templates/user/index.html.twig deleted file mode 100644 index 09e87fd..0000000 --- a/templates/user/index.html.twig +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'base.html.twig' %} - -{% block title %}Hello UserController!{% endblock %} - -{% block body %} - - -
-

Hello {{ controller_name }}! ✅

- - This friendly message is coming from: - -
-{% endblock %} diff --git a/templates/user/list.html.twig b/templates/user/list.html.twig new file mode 100644 index 0000000..e1f9e9b --- /dev/null +++ b/templates/user/list.html.twig @@ -0,0 +1,84 @@ +{% extends 'base.html.twig' %} + +{% block title %}Liste Utilisateur{% endblock %} + +{% block body %} + + +
+

Liste des Utilisateurs ! ✅

+ + + + + + + + + + + + + {% for utilisateur in utilisateurs %} + + + + + + + + {% else %} + + + + {% endfor %} + +
IDNomPrenomMailRoles
{{ utilisateur.id }}{{ utilisateur.nom }}{{ utilisateur.prenom }}{{ utilisateur.UserIdentifier }}{{ utilisateur.roles|join }}
Aucun utilisateur trouvé.
+
+ Ajouter un Utilisateur +
+
+{% endblock %} diff --git a/templates/user/user.html.twig b/templates/user/user.html.twig deleted file mode 100644 index e3d663b..0000000 --- a/templates/user/user.html.twig +++ /dev/null @@ -1,21 +0,0 @@ -{% extends 'base.html.twig' %} - -{% block stylesheets %} - -{% endblock %} - -{% block title %}AddUser{% endblock %} - -{% block body %} -

Register

- - {{ form_errors(registrationForm) }} - - {{ form_start(registrationForm) }} - {{ form_row(registrationForm.UserIdentifier) }} - {{ form_row(registrationForm.Password, { - label: 'Password' - }) }} - - {{ form_end(registrationForm) }} -{% endblock %} \ No newline at end of file