Browse Source

Mise a jour du formulaire d'inscription pour gérer le token d'inscription.

bastien 13 years ago
parent
commit
3632fb8df0

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

7
 email:     Email
7
 email:     Email
8
 password:
8
 password:
9
   first:   Mot de passe
9
   first:   Mot de passe
10
-  second:  Mot de passe (vérification)
10
+  second:  Mot de passe (vérification)
11
+token:     Code d'inscription
12
+
13
+help:
14
+  token:   |
15
+            Rentrez ici le code qui vous à été fournis afin de vous inscrire 
16
+            a la version non publique.

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

23
       notsame:           Vous avez saisie deux nouveaux mot de passes différents.
23
       notsame:           Vous avez saisie deux nouveaux mot de passes différents.
24
   changeemail:
24
   changeemail:
25
     email:
25
     email:
26
-      invalid:           L'email saisie n'est pas valide.
26
+      invalid:           L'email saisie n'est pas valide.
27
+      
28
+registration:
29
+  token:
30
+    error:               Le code saisie pour l'inscription n'est pas correct

+ 2 - 2
src/Muzich/IndexBundle/Resources/views/Index/index.html.twig View File

6
     
6
     
7
   <div class="hello">
7
   <div class="hello">
8
 
8
 
9
-    <div id="login_box">
9
+    <div id="login_box" style="{% if registration_page is defined %}display: none;{% endif %}">
10
       {% include "MuzichUserBundle:Security:login.html.twig" %}
10
       {% include "MuzichUserBundle:Security:login.html.twig" %}
11
         
11
         
12
       <a href="#" id="registration_link">
12
       <a href="#" id="registration_link">
14
       </a>
14
       </a>
15
     </div>
15
     </div>
16
     
16
     
17
-    <div id="registration_box" style="display: none;">
17
+    <div id="registration_box" style="{% if registration_page is not defined %}display: none;{% endif %}">
18
       {% include "MuzichUserBundle:Registration:register.html.twig" %}
18
       {% include "MuzichUserBundle:Registration:register.html.twig" %}
19
         
19
         
20
       <a href="#" id="login_link">
20
       <a href="#" id="login_link">

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

107
     $form_values = $this->getRequest()->request->get($form->getName());
107
     $form_values = $this->getRequest()->request->get($form->getName());
108
     $user = $form->getData();
108
     $user = $form->getData();
109
     
109
     
110
+    /**
111
+     * Contrôle du token
112
+     */
113
+    
114
+    $r_token = $this->getDoctrine()->getRepository('MuzichCoreBundle:RegistrationToken')
115
+      ->findOneBy(array('token' => $form_values["token"], 'used' => false))
116
+    ;
117
+      
118
+    if (!$r_token)
119
+    {
120
+      $errors[] = $this->get('translator')->trans(
121
+        'registration.token.error', 
122
+        array(),
123
+        'validators'
124
+      );
125
+    }
126
+    else
127
+    {
128
+      $r_token->setUsed(true);
129
+      $em = $this->getDoctrine()->getEntityManager();
130
+      $em->persist($r_token);
131
+      $em->flush();
132
+    }
133
+    
110
     /*
134
     /*
111
      * Contrôle de la taille du pseudo
135
      * Contrôle de la taille du pseudo
112
      * min: 3
136
      * min: 3
176
     return $this->container->get('templating')->renderResponse(
200
     return $this->container->get('templating')->renderResponse(
177
       'MuzichIndexBundle:Index:index.html.twig',
201
       'MuzichIndexBundle:Index:index.html.twig',
178
       array(
202
       array(
179
-        'form' => $form->createView(),
180
-        'error' => null,
181
-        'registration_errors' => $form->getErrors(),
203
+        'form'                     => $form->createView(),
204
+        'error'                    => null,
205
+        'registration_errors'      => $form->getErrors(),
182
         'registration_errors_pers' => $errors,
206
         'registration_errors_pers' => $errors,
183
-        'last_username' => null
207
+        'last_username'            => null,
208
+        'registration_page'        => true
184
       )
209
       )
185
     );
210
     );
186
   }
211
   }

+ 24 - 0
src/Muzich/UserBundle/Form/Type/RegistrationFormType.php View File

1
+<?php
2
+
3
+namespace Muzich\UserBundle\Form\Type;
4
+
5
+use Symfony\Component\Form\FormBuilder;
6
+use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;
7
+
8
+class RegistrationFormType extends BaseType
9
+{
10
+  public function buildForm(FormBuilder $builder, array $options)
11
+  {
12
+    parent::buildForm($builder, $options);
13
+
14
+    $builder->add('token', 'text', array(
15
+      "property_path" => false
16
+    ));
17
+    
18
+  }
19
+
20
+  public function getName()
21
+  {
22
+    return 'muzich_user_registration';
23
+  }
24
+}

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

39
       {{ form_label(form.plainPassword.second, 'password.second'|trans({}, 'userform')) }}
39
       {{ form_label(form.plainPassword.second, 'password.second'|trans({}, 'userform')) }}
40
       {{ form_widget(form.plainPassword.second) }}
40
       {{ form_widget(form.plainPassword.second) }}
41
     </div> 
41
     </div> 
42
+    
43
+    <span class="help">{{ 'help.token'|trans({}, 'userform') }}</span>
44
+    
45
+    <div class="field">
46
+      {{ form_errors(form.token) }}
47
+      {{ form_label(form.token, 'token'|trans({}, 'userform')) }}
48
+      {{ form_widget(form.token) }}
49
+    </div> 
42
 
50
 
43
     {{ form_rest(form) }}
51
     {{ form_rest(form) }}
44
     
52