Browse Source

Form change pass: récupération personaliser d'erreurs pour les afficher.

bastien 13 years ago
parent
commit
8b91523961

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

@@ -17,4 +17,7 @@ error:
17 17
       min:               Votre nom d'utilisateur doit contenir au moins %limit% caractères.
18 18
       max:               Votre nom d'utilisateur doit contenir au maximum %limit% caractères.
19 19
     password:
20
-      notsame:           Vous avez saisie deux mot de passes différents.
20
+      notsame:           Vous avez saisie deux mot de passes différents.
21
+  changepassword:
22
+    new:
23
+      notsame:           Vous avez saisie deux nouveaux mot de passes différents.

+ 33 - 4
src/Muzich/UserBundle/Controller/UserController.php View File

@@ -129,6 +129,35 @@ class UserController extends Controller
129 129
       )
130 130
     );
131 131
   }
132
+  
133
+  /**
134
+   * Un bug étrange empêche la mise ne place de contraintes sur le formulaire
135
+   * d'inscription. On effectue alors les vérifications ici.
136
+   * 
137
+   * C'est sale, mais ça marche ...
138
+   * 
139
+   * @return array of string errors
140
+   */
141
+  protected function checkChangePasswordInformations($form)
142
+  {
143
+    $errors = array();
144
+    $form_values = $this->getRequest()->request->get($form->getName());
145
+    $user = $form->getData();
146
+    
147
+    /**
148
+     * Mot de passes indentiques
149
+     */
150
+    if ($form_values['new']['first'] != $form_values['new']['second'])
151
+    {
152
+      $errors[] = $this->get('translator')->trans(
153
+        'error.changepassword.new.notsame', 
154
+        array(),
155
+        'validators'
156
+      );
157
+    }
158
+    
159
+    return $errors;
160
+  }
132 161
     
133 162
   public function changePasswordAction()
134 163
   {
@@ -153,8 +182,7 @@ class UserController extends Controller
153 182
     $form = $this->container->get('fos_user.change_password.form');
154 183
     $formHandler = $this->container->get('fos_user.change_password.form.handler');
155 184
     
156
-    $process = $formHandler->process($user);
157
-    if ($process)
185
+    if (count(($errors = $this->checkChangePasswordInformations($form))) < 1 && $process)
158 186
     {
159 187
       $this->container->get('session')->setFlash('fos_user_success', 'change_password.flash.success');
160 188
       return new RedirectResponse($this->generateUrl('my_account'));
@@ -172,8 +200,9 @@ class UserController extends Controller
172 200
       return $this->container->get('templating')->renderResponse(
173 201
         'MuzichUserBundle:User:account.html.twig',
174 202
         array(
175
-          'form_password' => $form->createView(),
176
-          'user' => $user,
203
+          'form_password'       => $form->createView(),
204
+          'errors_pers'         => $errors,
205
+          'user'                => $user,
177 206
           'form_tags_favorites' => $form_tags_favorites->createView()
178 207
         )
179 208
       );

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

@@ -7,6 +7,7 @@
7 7
     {% form_theme form 'MuzichCoreBundle:Form:errors.html.twig' %}
8 8
     
9 9
     {{ form_errors(form) }}
10
+    
10 11
     {% if registration_errors_pers|length > 0 %}
11 12
     <ul class="error_list">
12 13
       {% for error in registration_errors_pers %}

+ 13 - 3
src/Muzich/UserBundle/Resources/views/Security/change_password_form.html.twig View File

@@ -1,20 +1,30 @@
1
+{% form_theme form 'MuzichCoreBundle:Form:errors.html.twig' %}
2
+
1 3
 {{ form_errors(form) }}
4
+
5
+{% if errors_pers|length > 0 %}
6
+<ul class="error_list">
7
+  {% for error in errors_pers %}
8
+    <li>{{ error }}</li>
9
+  {% endfor %}
10
+</ul>
11
+{% endif %}
2 12
     
3 13
   <div class="field">
4
-    {{ form_label(form.current, 'password.actual'|trans({}, 'userform')) }}
5 14
     {{ form_errors(form.current) }}
15
+    {{ form_label(form.current, 'password.actual'|trans({}, 'userform')) }}
6 16
     {{ form_widget(form.current) }}
7 17
   </div>
8 18
 
9 19
   <div class="field">
10
-    {{ form_label(form.new.first, 'password.new.first'|trans({}, 'userform')) }}
11 20
     {{ form_errors(form.new.first) }}
21
+    {{ form_label(form.new.first, 'password.new.first'|trans({}, 'userform')) }}
12 22
     {{ form_widget(form.new.first) }}
13 23
   </div>
14 24
 
15 25
   <div class="field">
16
-    {{ form_label(form.new.second, 'password.new.second'|trans({}, 'userform')) }}
17 26
     {{ form_errors(form.new.second) }}
27
+    {{ form_label(form.new.second, 'password.new.second'|trans({}, 'userform')) }}
18 28
     {{ form_widget(form.new.second) }}
19 29
   </div>
20 30