Browse Source

bug fix: Il n'atait pas effectué de test de dulicité sur l'email lors de l'insciption ... :/

Sevajol Bastien 12 years ago
parent
commit
82dc2a935c

+ 3 - 0
app/Resources/translations/validators.en.yml View File

35
       tolong:            The name is too long.|The name is too long.
35
       tolong:            The name is too long.|The name is too long.
36
   url:
36
   url:
37
     invalid:             The URL is not a valid one.
37
     invalid:             The URL is not a valid one.
38
+  registration:
39
+    email:
40
+      duplicate:         Email address is already in use on muzi.ch
38
   
41
   
39
       
42
       
40
 registration:
43
 registration:

+ 3 - 0
app/Resources/translations/validators.fr.yml View File

35
       tolong:            Le nom est trop long
35
       tolong:            Le nom est trop long
36
   url:
36
   url:
37
     invalid:             L'adresse fournie est invalide
37
     invalid:             L'adresse fournie est invalide
38
+  registration:
39
+    email:
40
+      duplicate:         L'adresse email est déjà utilisé sur muzi.ch
38
   
41
   
39
       
42
       
40
 registration:
43
 registration:

+ 21 - 0
src/Muzich/CoreBundle/Entity/User.php View File

259
   public $mail_partner = true;
259
   public $mail_partner = true;
260
   
260
   
261
   /**
261
   /**
262
+   * @ORM\Column(type="boolean", nullable=true)
263
+   * @var type boolean
264
+   */
265
+  private $username_updatable = false;
266
+  
267
+  /**
262
    * 
268
    * 
263
    */
269
    */
264
   public function __construct()
270
   public function __construct()
1098
     ;
1104
     ;
1099
   }
1105
   }
1100
   
1106
   
1107
+  public function setUsernameUpdatable($updatable)
1108
+  {
1109
+    if ($updatable)
1110
+      $this->username_updatable = true;
1111
+    else
1112
+      $this->username_updatable = false;
1113
+  }
1114
+  
1115
+  public function isUsernameUpdateable()
1116
+  {
1117
+    if ($this->username_updatable)
1118
+      return true;
1119
+    return false;
1120
+  }
1121
+  
1101
 }
1122
 }

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

137
     $user = $this->getNewUser($userManager);
137
     $user = $this->getNewUser($userManager);
138
     $form = $this->getRegistrationForm($user);
138
     $form = $this->getRegistrationForm($user);
139
     $form->bindRequest($request);
139
     $form->bindRequest($request);
140
+    $errors = $this->checkRegistrationValues($form);
140
     
141
     
141
-    if ($form->isValid())
142
+    if ($form->isValid() && !count($errors))
142
     {
143
     {
143
       $response = $this->getSuccessRegistrationResponse();
144
       $response = $this->getSuccessRegistrationResponse();
144
       $userManager->updateUser($user);
145
       $userManager->updateUser($user);
146
       return $response;
147
       return $response;
147
     }
148
     }
148
     
149
     
149
-    return $this->getFailureRegistrationResponse($form);
150
+    return $this->getFailureRegistrationResponse($form, $errors);
150
   }
151
   }
151
   
152
   
152
   protected function getRegistrationForm(User $user)
153
   protected function getRegistrationForm(User $user)
163
     $user->setPlainPassword($this->generatePassword(32));
164
     $user->setPlainPassword($this->generatePassword(32));
164
     $user->setEnabled(true);
165
     $user->setEnabled(true);
165
     $user->setCguAccepted(true);
166
     $user->setCguAccepted(true);
167
+    $user->setUsernameUpdatable(true);
166
     return $user;
168
     return $user;
167
   }
169
   }
168
   
170
   
188
     return $result;
190
     return $result;
189
   }
191
   }
190
   
192
   
193
+  protected function checkRegistrationValues($form)
194
+  {
195
+    $count = $this->getEntityManager()->createQuery("SELECT count(u.id) "
196
+      ."FROM MuzichCoreBundle:User u "
197
+      ."WHERE UPPER(u.email) = :email_canonical")
198
+      ->setParameter('email_canonical', strtoupper($form->getData()->getEmailCanonical()))
199
+      ->getSingleScalarResult()
200
+    ;
201
+    
202
+    if ($count)
203
+    {
204
+      return array($this->trans('error.registration.email.duplicate', array(), 'validators'));
205
+    }
206
+    return array();
207
+  }
208
+  
191
   protected function getSuccessRegistrationResponse()
209
   protected function getSuccessRegistrationResponse()
192
   {
210
   {
193
     if (!$this->getRequest()->isXmlHttpRequest())
211
     if (!$this->getRequest()->isXmlHttpRequest())
201
     ));
219
     ));
202
   }
220
   }
203
   
221
   
204
-  protected function getFailureRegistrationResponse($form)//, $formHandler)
222
+  protected function getFailureRegistrationResponse($form, $errors = array())//, $formHandler)
205
   {
223
   {
206
     $parameters = array(
224
     $parameters = array(
207
       'form'                     => $form->createView(),
225
       'form'                     => $form->createView(),
208
       'error'                    => null,
226
       'error'                    => null,
209
       'registration_errors'      => $form->getErrors(),
227
       'registration_errors'      => $form->getErrors(),
210
-      //'registration_errors_pers' => $formHandler->getErrors(),
228
+      'registration_errors_pers' => $errors,
211
       'last_username'            => null,
229
       'last_username'            => null,
212
       'registration_page'        => true,
230
       'registration_page'        => true,
213
       'presubscription_form'     => $this->getPreSubscriptionForm()->createView()
231
       'presubscription_form'     => $this->getPreSubscriptionForm()->createView()

+ 7 - 10
src/Muzich/UserBundle/Form/Type/RegistrationFormType.php View File

10
 {
10
 {
11
   public function buildForm(FormBuilderInterface $builder, array $options)
11
   public function buildForm(FormBuilderInterface $builder, array $options)
12
   {
12
   {
13
-    $builder->add('email', 'email', array(
14
-      'label' => 'form.email',
15
-      'translation_domain' => 'FOSUserBundle'
16
-    ));
13
+    $builder->add('email', 'email');
17
   }
14
   }
18
   
15
   
19
-  //public function setDefaultOptions(OptionsResolverInterface $resolver)
20
-  //{
21
-  //  $resolver->setDefaults(array(
22
-  //    'data_class' => 'Muzich\CoreBundle\Entity\User'
23
-  //  ));
24
-  //}
16
+  public function setDefaultOptions(OptionsResolverInterface $resolver)
17
+  {
18
+    $resolver->setDefaults(array(
19
+      'data_class' => 'Muzich\CoreBundle\Entity\User'
20
+    ));
21
+  }
25
   
22
   
26
   public function getName()
23
   public function getName()
27
   {
24
   {

+ 3 - 1
src/Muzich/UserBundle/Resources/views/Info/bar.html.twig View File

15
 <ul class="user_events_infos">
15
 <ul class="user_events_infos">
16
 
16
 
17
   <li class="user_name">
17
   <li class="user_name">
18
-    {{ app.user.name }}
18
+    <a href="{{ path('my_account') }}">
19
+      {{ app.user.name }}
20
+    </a>
19
   </li>
21
   </li>
20
 
22
 
21
   <li class="user_messages">
23
   <li class="user_messages">