Эх сурвалжийг харах

page publique d'enregistrement nettoyée

garthh 1 долоо хоног өмнө
parent
commit
27bf1883ac

+ 23 - 3
src/Controller/RegistrationController.php

@@ -17,6 +17,7 @@ use Symfony\Component\Routing\Attribute\Route;
 use Symfony\Contracts\Translation\TranslatorInterface;
 use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface;
 use Symfony\Component\Routing\Requirement\Requirement;
+use Symfony\Component\Mailer\MailerInterface;
 
 class RegistrationController extends AbstractController
 {
@@ -25,8 +26,15 @@ class RegistrationController extends AbstractController
     }
 
     #[Route('/register', name: 'app_register')]
-    public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response
+    public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, MailerInterface $mailer): Response
     {
+
+        // SI l'utilisateur est déjà connecté, rediriger vers la page d'accueil
+        if ($this->getUser()) {
+            $this->addFlash('info', 'Vous êtes déjà connecté. Vous ne pouvez pas vous enregistrer à nouveau.');
+            return $this->redirectToRoute('app_main');
+        }
+
         $user = new User();
         $form = $this->createForm(RegistrationFormType::class, $user);
         $form->handleRequest($request);
@@ -51,11 +59,23 @@ class RegistrationController extends AbstractController
                     ->htmlTemplate('registration/confirmation_email.html.twig')
                     ->textTemplate('registration/confirmation_email.txt.twig')
             );
+            $email = (new TemplatedEmail())
+                ->from(new Address($_ENV['CONTACT_EMAIL'], $_ENV['CONTACT_NAME']))
+                ->to((string) $user->getEmail())
+                ->subject('Votre compte a été créé')
+                ->htmlTemplate('admin/user/add.email.html.twig')
+                ->textTemplate('admin/user/add.email.txt.twig')
+                ->context([
+                    'user' => $user,
+                    'clearPassword' => $plainPassword,
+                ]);
+            $mailer->send($email);
 
             // do anything else you need here, like send an email
 
+
             $this->addFlash('success', 'Votre compte a été créé avec succès. Veuillez vérifier votre email pour confirmer votre adresse.');
-            return $this->redirectToRoute('app_main');
+            return $this->redirectToRoute('app_login');
         }
 
         return $this->render('registration/register.html.twig', [
@@ -76,7 +96,7 @@ class RegistrationController extends AbstractController
         );
 
         $this->addFlash('success', 'Un nouvel email de confirmation a été envoyé à votre adresse email.');
-        return $this->redirectToRoute('app_admin_user');
+        return $this->redirectToRoute('app_login');
 
     }
 

+ 45 - 30
src/Form/RegistrationFormType.php

@@ -18,18 +18,57 @@ class RegistrationFormType extends AbstractType
     public function buildForm(FormBuilderInterface $builder, array $options): void
     {
         $builder
-            ->add('firstName')
-            ->add('lastName')
+            ->add('firstName', null, [
+                'label' => 'Prénom',
+                'required' => true,
+                'help' => 'Entrez le prénom de l\'utilisateur.'
+            ])
+            ->add('lastName', null, [
+                'label' => 'Nom',
+                'required' => true,
+                'help' => 'Entrez le nom de l\'utilisateur.'
+            ])
+            ->add('email', null, [
+                'label' => 'eMail',
+                'required' => true,
+                'help' => 'Entrez une adresse email.'
+            ])
             ->add('phone', null, [
+                'label' => 'Téléphone',
                 'required' => false,
-                'label' => 'Phone Number',
+                'help' => 'Entrez un numéro de téléphone (optionnel).'
+            ])
+            ->add('plainPassword', RepeatedType::class, [
+                'mapped' => false,
+                'invalid_message' => 'Les mots de passe ne sont pas identiques.',
+                'type' => PasswordType::class,
+                'first_options' => [
+                    'label' => 'Mot de passe',
+                    'toggle' => true,
+                    'attr' => ['autocomplete' => 'new-password'],
+                    'constraints' => [
+                        new NotBlank([
+                            'message' => 'Merci d\'entrer un mot de passe.',
+                        ]),
+                        new Length([
+                            'min' => 6,
+                            'minMessage' => 'Votre mot de passe doit contenir au moins {{ limit }} caractères',
+                            // max length allowed by Symfony for security reasons
+                            'max' => 4096,
+                        ]),
+                    ]],
+                'second_options' => [
+                    'label' => 'Répéter le mot de passe',
+                    'toggle' => true,
+                    'attr' => ['autocomplete' => 'new-password'],
+                    ],
             ])
-            ->add('email')
             ->add('agreeTerms', CheckboxType::class, [
+                'label' => 'J\'accepte les conditions d\'utilisation du service.',
                 'mapped' => false,
                 'constraints' => [
                     new IsTrue([
-                        'message' => 'You should agree to our terms.',
+                        'message' => 'Vous devez accepter les conditions d\'utilisation du service.',
                     ]),
                 ],
             ])
@@ -51,31 +90,7 @@ class RegistrationFormType extends AbstractType
                     ]),
                 ],
             ]) */
-            ->add('plainPassword', RepeatedType::class, [
-                'mapped' => false,
-                'invalid_message' => 'The password fields must match.',
-                'type' => PasswordType::class,
-                'first_options' => [
-                    'label' => 'Password',
-                    'toggle' => true,
-                    '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,
-                        ]),
-                    ]],
-                'second_options' => [
-                    'label' => 'Repeat Password',
-                    'toggle' => true,
-                    'attr' => ['autocomplete' => 'new-password'],
-                    ],
-            ])
+
         ;
     }
 

+ 1 - 1
src/Form/UserType.php

@@ -64,7 +64,7 @@ class UserType extends AbstractType
                     'constraints' => [
                         new Length([
                             'min' => 6,
-                            'minMessage' => 'Your password should be at least {{ limit }} characters',
+                            'minMessage' => 'Votre mot de passe doit contenir au moins {{ limit }} caractères',
                             // max length allowed by Symfony for security reasons
                             'max' => 4096,
                         ]),

+ 4 - 8
templates/registration/register.html.twig

@@ -1,23 +1,19 @@
 {% extends 'base.html.twig' %}
 
-{% block title %}Register{% endblock %}
+{% block title %}S'enregistrer{% endblock %}
 
 {% block content %}
     {% for flash_error in app.flashes('verify_email_error') %}
         <div class="alert alert-danger" role="alert">{{ flash_error }}</div>
     {% endfor %}
 
-    <h1>Register</h1>
+    <h1>S'enregistrer</h1>
 
     {{ form_errors(registrationForm) }}
 
     {{ form_start(registrationForm) }}
-        {{ form_row(registrationForm.email) }}
-        {{ form_row(registrationForm.plainPassword, {
-            label: 'Password'
-        }) }}
-        {{ form_row(registrationForm.agreeTerms) }}
 
-        <button type="submit" class="btn">Register</button>
+        <button type="submit" class="btn">S'enregistrer</button>
+        <a href="{{ path('app_main') }}" class="btn btn-secondary">Annuler</a>
     {{ form_end(registrationForm) }}
 {% endblock %}

+ 1 - 1
templates/security/login.html.twig

@@ -32,7 +32,7 @@
             </div>
 
             <div>
-                <a href="{{ path('app_forgot_password_request') }}">Forgot password?</a>
+                <a href="{{ path('app_forgot_password_request') }}">Forgot password?</a> | <a href="{{ path('app_register') }}">Register</a>
             </div>
         {# #}