Browse Source

Anomalie #34: Form: Inscription

bastien 12 years ago
parent
commit
e11ca0a1b5

+ 5 - 1
app/Resources/translations/validators.fr.yml View File

@@ -9,4 +9,8 @@
9 9
 error:
10 10
   group:
11 11
     name:
12
-      unique:            Ce nom est déjà utilisé pour un autre groupe
12
+      unique:            Ce nom est déjà utilisé pour un autre groupe
13
+  registration:
14
+    username:
15
+      min:               Votre nom d'utilisateur doit contenir au moins %limit% caractères 
16
+      max:               Votre nom d'utilisateur doit contenir au maximum %limit% caractères 

+ 1 - 0
src/Muzich/IndexBundle/Controller/IndexController.php View File

@@ -57,6 +57,7 @@ class IndexController extends Controller
57 57
     return array(
58 58
         'last_username' => $lastUsername,
59 59
         'error'         => $error,
60
+        'registration_errors_pers' => array()
60 61
     );
61 62
   }
62 63
   

+ 56 - 13
src/Muzich/UserBundle/Controller/UserController.php View File

@@ -37,28 +37,70 @@ class UserController extends Controller
37 37
       );
38 38
   }
39 39
   
40
+  /**
41
+   * Un bug étrange empêche la mise ne place de contraintes sur le formulaire
42
+   * d'inscription. On effectue alors les vérifications ici.
43
+   * 
44
+   * @return array of string errors
45
+   */
46
+  protected function checkRegistrationInformations($form)
47
+  {
48
+    $errors = array();
49
+    $form->bindRequest($this->getRequest());
50
+    $user = $form->getData();
51
+    
52
+    /*
53
+     * Contrôle de la taille du pseudo
54
+     * min: 3
55
+     * max: 32
56
+     */
57
+    if (strlen($user->getUsername()) < 3)
58
+    {
59
+      $errors[] = $this->get('translator')->trans(
60
+        'error.registration.username.min', 
61
+        array('%limit%' => 3),
62
+        'validators'
63
+      );
64
+    }
65
+    
66
+    if (strlen($user->getUsername()) > 32)
67
+    {
68
+      $errors[] = $this->get('translator')->trans(
69
+        'error.registration.username.max', 
70
+        array('%limit%' => 32),
71
+        'validators'
72
+      );
73
+    }
74
+    
75
+    return $errors;
76
+  }
77
+  
40 78
   public function registerAction()
41 79
   {
42 80
     $form = $this->container->get('fos_user.registration.form');
43 81
     $formHandler = $this->container->get('fos_user.registration.form.handler');
44 82
     $confirmationEnabled = $this->container->getParameter('fos_user.registration.confirmation.enabled');
45 83
     
46
-    $process = $formHandler->process($confirmationEnabled);
47
-    if ($process) {
48
-      $user = $form->getData();
84
+    // Pour palier bug, verif interne
85
+    if (count(($errors = $this->checkRegistrationInformations($form))) < 1)
86
+    {
87
+      $process = $formHandler->process($confirmationEnabled);
88
+      if ($process) {
89
+        $user = $form->getData();
49 90
 
50
-      if ($confirmationEnabled) {
51
-        $this->container->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail());
52
-        $route = 'fos_user_registration_check_email';
53
-      } else {
54
-        $this->authenticateUser($user);
55
-        $route = 'start';
56
-      }
91
+        if ($confirmationEnabled) {
92
+          $this->container->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail());
93
+          $route = 'fos_user_registration_check_email';
94
+        } else {
95
+          $this->authenticateUser($user);
96
+          $route = 'start';
97
+        }
57 98
 
58
-      $this->setFlash('fos_user_success', 'registration.flash.user_created');
59
-      $url = $this->generateUrl($route);
99
+        $this->setFlash('fos_user_success', 'registration.flash.user_created');
100
+        $url = $this->generateUrl($route);
60 101
 
61
-      return new RedirectResponse($url);
102
+        return new RedirectResponse($url);
103
+      }
62 104
     }
63 105
 
64 106
     return $this->container->get('templating')->renderResponse(
@@ -67,6 +109,7 @@ class UserController extends Controller
67 109
         'form' => $form->createView(),
68 110
         'error' => null,
69 111
         'registration_errors' => $form->getErrors(),
112
+        'registration_errors_pers' => $errors,
70 113
         'last_username' => null
71 114
       )
72 115
     );

+ 9 - 1
src/Muzich/UserBundle/Resources/views/Registration/register.html.twig View File

@@ -7,12 +7,20 @@
7 7
     
8 8
     {% if form.get("errors")|length > 0 %}
9 9
     <ul class="error_list">
10
-      {% for key, error in form.get("errors") %}
10
+      {% for error in form.get("errors") %}
11 11
         <li>{{ error.messageTemplate|trans(error.messageParameters, 'validators') }}</li>
12 12
       {% endfor %}
13 13
     </ul>
14 14
     {% endif %}
15 15
     
16
+    {% if registration_errors_pers|length > 0 %}
17
+    <ul class="error_list">
18
+      {% for error in registration_errors_pers %}
19
+        <li>{{ error }}</li>
20
+      {% endfor %}
21
+    </ul>
22
+    {% endif %}
23
+    
16 24
     {{ form_row(form.username) }}
17 25
     
18 26
     {{ form_row(form.email) }}