Browse Source

Merge branch 'feature/token' into unstable

bastien 13 years ago
parent
commit
775fa47d42

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

@@ -7,4 +7,10 @@ username:  Nom d'utilisateur
7 7
 email:     Email
8 8
 password:
9 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,4 +23,8 @@ error:
23 23
       notsame:           Vous avez saisie deux nouveaux mot de passes différents.
24 24
   changeemail:
25 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

+ 43 - 0
src/Muzich/AdminBundle/Admin/RegistrationTokenAdmin.php View File

@@ -0,0 +1,43 @@
1
+<?php
2
+
3
+namespace Muzich\AdminBundle\Admin;
4
+
5
+use Sonata\AdminBundle\Admin\Admin;
6
+use Sonata\AdminBundle\Form\FormMapper;
7
+use Sonata\AdminBundle\Datagrid\DatagridMapper;
8
+use Sonata\AdminBundle\Datagrid\ListMapper;
9
+
10
+class RegistrationTokenAdmin extends Admin
11
+{
12
+  
13
+  protected function configureListFields(ListMapper $listMapper)
14
+  {
15
+    $listMapper
16
+      ->addIdentifier('id')
17
+      ->addIdentifier('token')
18
+      ->add('_action', 'actions', array(
19
+        'actions' => array(
20
+          'view' => array(),
21
+          'edit' => array(),
22
+        )
23
+      ))
24
+    ;
25
+  }
26
+  
27
+  protected function configureDatagridFilters(DatagridMapper $datagrid)
28
+  {
29
+    $datagrid
30
+      ->add('token')
31
+      ->add('used')
32
+    ;
33
+  }
34
+  
35
+  protected function configureFormFields(FormMapper $formMapper)
36
+  {
37
+    $formMapper
38
+      ->add('token')
39
+      ->add('used')
40
+    ;
41
+  }
42
+  
43
+}

+ 9 - 0
src/Muzich/AdminBundle/Controller/RegistrationTokenAdminController.php View File

@@ -0,0 +1,9 @@
1
+<?php
2
+
3
+namespace Muzich\AdminBundle\Controller;
4
+
5
+use Sonata\AdminBundle\Controller\CRUDController as Controller;
6
+
7
+class RegistrationTokenAdminController extends Controller
8
+{
9
+}

+ 100 - 0
src/Muzich/CoreBundle/Entity/RegistrationToken.php View File

@@ -0,0 +1,100 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Entity;
4
+
5
+use Doctrine\ORM\Mapping as ORM;
6
+use Symfony\Component\Validator\Constraints as Assert;
7
+use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
8
+
9
+/**
10
+ * Le RegistrationToken sert uniquement a contrôler les inscription durant 
11
+ * toute la phase fermé du site en production.
12
+ * 
13
+ * @ORM\Entity
14
+ * @UniqueEntity(fields="token")
15
+ */
16
+class RegistrationToken
17
+{
18
+  
19
+  /**
20
+   * @ORM\Id
21
+   * @ORM\Column(type="integer")
22
+   * @ORM\GeneratedValue(strategy="AUTO")
23
+   * @var type int
24
+   */
25
+  protected $id;
26
+  
27
+  /**
28
+   * Le token en question
29
+   * 
30
+   * @ORM\Column(type="string", length=32, unique=true)
31
+   * @Assert\NotBlank()
32
+   * @Assert\MinLength(limit=3)
33
+   * @Assert\MaxLength(32)
34
+   * @var type string
35
+   */
36
+  protected $token;
37
+  
38
+  /**
39
+   * Si ce boolean est a vrai il n'est plus utilisable
40
+   * @ORM\Column(type="boolean", nullable=true)
41
+   * @var type boolean
42
+   */
43
+  protected $used = false;
44
+    
45
+  public function __toString()
46
+  {
47
+    return $this->getToken();
48
+  }
49
+  
50
+  /**
51
+   * Get id
52
+   *
53
+   * @return integer 
54
+   */
55
+  public function getId()
56
+  {
57
+    return $this->id;
58
+  }
59
+
60
+  /**
61
+   * Set token
62
+   *
63
+   * @param string $token
64
+   */
65
+  public function setToken($token)
66
+  {
67
+    $this->token = $token;
68
+  }
69
+
70
+  /**
71
+   * Get token
72
+   *
73
+   * @return string 
74
+   */
75
+  public function getToken()
76
+  {
77
+    return $this->token;
78
+  }
79
+
80
+  /**
81
+   * Set used
82
+   *
83
+   * @param boolean $used
84
+   */
85
+  public function setUsed($used)
86
+  {
87
+    $this->used = $used;
88
+  }
89
+
90
+  /**
91
+   * Get used
92
+   *
93
+   * @return boolean 
94
+   */
95
+  public function getUsed()
96
+  {
97
+    return $this->used;
98
+  }
99
+
100
+}

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

@@ -6,7 +6,7 @@
6 6
     
7 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 10
       {% include "MuzichUserBundle:Security:login.html.twig" %}
11 11
         
12 12
       <a href="#" id="registration_link">
@@ -14,7 +14,7 @@
14 14
       </a>
15 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 18
       {% include "MuzichUserBundle:Registration:register.html.twig" %}
19 19
         
20 20
       <a href="#" id="login_link">

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

@@ -107,6 +107,30 @@ class UserController extends Controller
107 107
     $form_values = $this->getRequest()->request->get($form->getName());
108 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 135
      * Contrôle de la taille du pseudo
112 136
      * min: 3
@@ -176,11 +200,12 @@ class UserController extends Controller
176 200
     return $this->container->get('templating')->renderResponse(
177 201
       'MuzichIndexBundle:Index:index.html.twig',
178 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 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

@@ -0,0 +1,24 @@
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,6 +39,14 @@
39 39
       {{ form_label(form.plainPassword.second, 'password.second'|trans({}, 'userform')) }}
40 40
       {{ form_widget(form.plainPassword.second) }}
41 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 51
     {{ form_rest(form) }}
44 52