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
       min:               Votre nom d'utilisateur doit contenir au moins %limit% caractères.
17
       min:               Votre nom d'utilisateur doit contenir au moins %limit% caractères.
18
       max:               Votre nom d'utilisateur doit contenir au maximum %limit% caractères.
18
       max:               Votre nom d'utilisateur doit contenir au maximum %limit% caractères.
19
     password:
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
       )
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
   public function changePasswordAction()
162
   public function changePasswordAction()
134
   {
163
   {
153
     $form = $this->container->get('fos_user.change_password.form');
182
     $form = $this->container->get('fos_user.change_password.form');
154
     $formHandler = $this->container->get('fos_user.change_password.form.handler');
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
       $this->container->get('session')->setFlash('fos_user_success', 'change_password.flash.success');
187
       $this->container->get('session')->setFlash('fos_user_success', 'change_password.flash.success');
160
       return new RedirectResponse($this->generateUrl('my_account'));
188
       return new RedirectResponse($this->generateUrl('my_account'));
172
       return $this->container->get('templating')->renderResponse(
200
       return $this->container->get('templating')->renderResponse(
173
         'MuzichUserBundle:User:account.html.twig',
201
         'MuzichUserBundle:User:account.html.twig',
174
         array(
202
         array(
175
-          'form_password' => $form->createView(),
176
-          'user' => $user,
203
+          'form_password'       => $form->createView(),
204
+          'errors_pers'         => $errors,
205
+          'user'                => $user,
177
           'form_tags_favorites' => $form_tags_favorites->createView()
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
     {% form_theme form 'MuzichCoreBundle:Form:errors.html.twig' %}
7
     {% form_theme form 'MuzichCoreBundle:Form:errors.html.twig' %}
8
     
8
     
9
     {{ form_errors(form) }}
9
     {{ form_errors(form) }}
10
+    
10
     {% if registration_errors_pers|length > 0 %}
11
     {% if registration_errors_pers|length > 0 %}
11
     <ul class="error_list">
12
     <ul class="error_list">
12
       {% for error in registration_errors_pers %}
13
       {% for error in registration_errors_pers %}

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

1
+{% form_theme form 'MuzichCoreBundle:Form:errors.html.twig' %}
2
+
1
 {{ form_errors(form) }}
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
   <div class="field">
13
   <div class="field">
4
-    {{ form_label(form.current, 'password.actual'|trans({}, 'userform')) }}
5
     {{ form_errors(form.current) }}
14
     {{ form_errors(form.current) }}
15
+    {{ form_label(form.current, 'password.actual'|trans({}, 'userform')) }}
6
     {{ form_widget(form.current) }}
16
     {{ form_widget(form.current) }}
7
   </div>
17
   </div>
8
 
18
 
9
   <div class="field">
19
   <div class="field">
10
-    {{ form_label(form.new.first, 'password.new.first'|trans({}, 'userform')) }}
11
     {{ form_errors(form.new.first) }}
20
     {{ form_errors(form.new.first) }}
21
+    {{ form_label(form.new.first, 'password.new.first'|trans({}, 'userform')) }}
12
     {{ form_widget(form.new.first) }}
22
     {{ form_widget(form.new.first) }}
13
   </div>
23
   </div>
14
 
24
 
15
   <div class="field">
25
   <div class="field">
16
-    {{ form_label(form.new.second, 'password.new.second'|trans({}, 'userform')) }}
17
     {{ form_errors(form.new.second) }}
26
     {{ form_errors(form.new.second) }}
27
+    {{ form_label(form.new.second, 'password.new.second'|trans({}, 'userform')) }}
18
     {{ form_widget(form.new.second) }}
28
     {{ form_widget(form.new.second) }}
19
   </div>
29
   </div>
20
 
30