Browse Source

Evolution #582: Implémenter le mode nopass

Sevajol Bastien 12 years ago
parent
commit
96570f0c56

+ 3 - 1
app/Resources/translations/userform.en.yml View File

1
 
1
 
2
 password.actual: Actual
2
 password.actual: Actual
3
 password.new.first: New
3
 password.new.first: New
4
-password.new.second: New (check)
4
+password.new.second: New (check)
5
+
6
+accept_cgu_registration: By processing registration you accept <a href="%link%">terms of service</a> of muzi.ch

+ 3 - 1
app/Resources/translations/userform.fr.yml View File

16
 help:
16
 help:
17
   token:   |
17
   token:   |
18
             Rentrez ici le code qui vous à été fourni afin de vous inscrire 
18
             Rentrez ici le code qui vous à été fourni afin de vous inscrire 
19
-            à la version non publique.
19
+            à la version non publique.
20
+
21
+accept_cgu_registration: En procédant à l'inscription vous acceptez les <a href="%link%">conditions générales d'utilisation</a> de muzi.ch

+ 5 - 0
src/Muzich/CoreBundle/Resources/public/css/main.css View File

2050
 div.side_margin_top
2050
 div.side_margin_top
2051
 {
2051
 {
2052
   margin-top: 25px;
2052
   margin-top: 25px;
2053
+}
2054
+
2055
+p.accept_cgu
2056
+{
2057
+  font-size: 11px;
2053
 }
2058
 }

+ 9 - 2
src/Muzich/IndexBundle/Controller/IndexController.php View File

8
 use Symfony\Component\Validator\Constraints\Email;
8
 use Symfony\Component\Validator\Constraints\Email;
9
 use Symfony\Component\Validator\Constraints\Collection;
9
 use Symfony\Component\Validator\Constraints\Collection;
10
 use Symfony\Component\HttpFoundation\Request;
10
 use Symfony\Component\HttpFoundation\Request;
11
+use Muzich\UserBundle\Form\Type\RegistrationFormType;
12
+use Muzich\CoreBundle\Entity\User;
11
 
13
 
12
 class IndexController extends Controller
14
 class IndexController extends Controller
13
 {
15
 {
25
     }
27
     }
26
     
28
     
27
     $vars = $this->proceedLogin();
29
     $vars = $this->proceedLogin();
28
-    $form = $this->container->get('fos_user.registration.form');
30
+    $form = $this->getRegistrationForm();
29
     
31
     
30
     return $this->render('MuzichIndexBundle:Index:index.html.twig', array_merge($vars, array(
32
     return $this->render('MuzichIndexBundle:Index:index.html.twig', array_merge($vars, array(
31
       'form' => $form->createView(),
33
       'form' => $form->createView(),
33
     )));
35
     )));
34
   }
36
   }
35
   
37
   
38
+  protected function getRegistrationForm()
39
+  {
40
+    return $this->createForm(new RegistrationFormType(), new User());
41
+  }
42
+  
36
   /**
43
   /**
37
    * Gestion du formulaire d'identification sur la page d'index.
44
    * Gestion du formulaire d'identification sur la page d'index.
38
    * 
45
    * 
104
     
111
     
105
     $this->setFlash('error', 'presubscription.error');
112
     $this->setFlash('error', 'presubscription.error');
106
     return $this->render('MuzichIndexBundle:Index:index.html.twig', array(
113
     return $this->render('MuzichIndexBundle:Index:index.html.twig', array(
107
-      'form' => $this->container->get('fos_user.registration.form')->createView(),
114
+      'form' => $this->getRegistrationForm()->createView(),
108
       'presubscription_form' => $form->createView(),
115
       'presubscription_form' => $form->createView(),
109
       'last_username' => '',
116
       'last_username' => '',
110
       'error'         => '',
117
       'error'         => '',

+ 9 - 39
src/Muzich/UserBundle/Controller/UserController.php View File

135
   {
135
   {
136
     $userManager = $this->container->get('fos_user.user_manager');
136
     $userManager = $this->container->get('fos_user.user_manager');
137
     $user = $this->getNewUser($userManager);
137
     $user = $this->getNewUser($userManager);
138
-    $form = $this->createForm(new RegistrationFormType(), $user);
138
+    $form = $this->getRegistrationForm($user);
139
     $form->bindRequest($request);
139
     $form->bindRequest($request);
140
     
140
     
141
     if ($form->isValid())
141
     if ($form->isValid())
149
     return $this->getFailureRegistrationResponse($form);
149
     return $this->getFailureRegistrationResponse($form);
150
   }
150
   }
151
   
151
   
152
+  protected function getRegistrationForm(User $user)
153
+  {
154
+    return $this->createForm(new RegistrationFormType(), $user);
155
+  }
156
+  
152
   /** @return User */
157
   /** @return User */
153
-  protected function getNewUser($userManager)
158
+  protected function getNewUser()
154
   {
159
   {
160
+    $userManager = $this->container->get('fos_user.user_manager');
155
     $user = $userManager->createUser();
161
     $user = $userManager->createUser();
156
     $user->setUsername($this->generateUsername());
162
     $user->setUsername($this->generateUsername());
157
     $user->setPlainPassword($this->generatePassword(32));
163
     $user->setPlainPassword($this->generatePassword(32));
182
     return $result;
188
     return $result;
183
   }
189
   }
184
   
190
   
185
-  public function registerOldAction()
186
-  {
187
-    $form = $this->container->get('fos_user.registration.form');
188
-    $formHandler = $this->container->get('fos_user.registration.form.handler');
189
-    $confirmationEnabled = $this->container->getParameter('fos_user.registration.confirmation.enabled');
190
-    
191
-    $process = $formHandler->process($confirmationEnabled);
192
-    if ($process)
193
-    {
194
-      $user = $form->getData();
195
-      
196
-      $authUser = false;
197
-      if ($confirmationEnabled) {
198
-          $this->container->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail());
199
-          $route = 'fos_user_registration_check_email';
200
-      } else {
201
-          $authUser = true;
202
-          $route = 'start';
203
-      }
204
-      
205
-      $response = $this->getSuccessRegistrationResponse();
206
-      if ($authUser) {
207
-        $this->authenticateUser($user, $response);
208
-      }
209
-      
210
-      $formHandler->getToken()->addUseCount();
211
-      $em = $this->getDoctrine()->getEntityManager();
212
-      $em->persist($formHandler->getToken());
213
-      $em->flush();
214
-      
215
-      return $response;
216
-    }
217
-    
218
-    return $this->getFailureRegistrationResponse($form, $formHandler);
219
-  }
220
-  
221
   protected function getSuccessRegistrationResponse()
191
   protected function getSuccessRegistrationResponse()
222
   {
192
   {
223
     if (!$this->getRequest()->isXmlHttpRequest())
193
     if (!$this->getRequest()->isXmlHttpRequest())
692
     return $this->jsonResponse(array(
662
     return $this->jsonResponse(array(
693
       'status' => 'success',
663
       'status' => 'success',
694
       'data'   => $this->render('MuzichUserBundle:Account:subscribe_or_login.html.twig', array(
664
       'data'   => $this->render('MuzichUserBundle:Account:subscribe_or_login.html.twig', array(
695
-        'form' => $this->container->get('fos_user.registration.form')->createView()
665
+        'form' => $this->getRegistrationForm($this->getNewUser())->createView()
696
       ))->getContent()
666
       ))->getContent()
697
     ));
667
     ));
698
   }
668
   }

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

20
   {{ form_widget(form.email, {'attr':{'class':'niceinput'}}) }}
20
   {{ form_widget(form.email, {'attr':{'class':'niceinput'}}) }}
21
 </div> 
21
 </div> 
22
 
22
 
23
-{{ form_rest(form) }}
23
+{{ form_widget(form._token) }}
24
 
24
 
25
 <div class="alignright">
25
 <div class="alignright">
26
   <img class="loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading" />
26
   <img class="loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading" />
27
   <input type="submit" class="button" value="{{ 'registration.submit'|trans({}, 'userui') }}" />
27
   <input type="submit" class="button" value="{{ 'registration.submit'|trans({}, 'userui') }}" />
28
 </div>
28
 </div>
29
+
30
+<p class="accept_cgu">
31
+  {% autoescape false %}
32
+    {{ 'accept_cgu_registration'|trans({
33
+      '%link%' : path('info_cgu')
34
+    }, 'userform' )}}
35
+  {% endautoescape %}
36
+</p>