Bladeren bron

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

Sevajol Bastien 11 jaren geleden
bovenliggende
commit
82dc2a935c

+ 3 - 0
app/Resources/translations/validators.en.yml Bestand weergeven

@@ -35,6 +35,9 @@ error:
35 35
       tolong:            The name is too long.|The name is too long.
36 36
   url:
37 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 43
 registration:

+ 3 - 0
app/Resources/translations/validators.fr.yml Bestand weergeven

@@ -35,6 +35,9 @@ error:
35 35
       tolong:            Le nom est trop long
36 36
   url:
37 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 43
 registration:

+ 21 - 0
src/Muzich/CoreBundle/Entity/User.php Bestand weergeven

@@ -259,6 +259,12 @@ class User extends BaseUser
259 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 270
   public function __construct()
@@ -1098,4 +1104,19 @@ class User extends BaseUser
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 Bestand weergeven

@@ -137,8 +137,9 @@ class UserController extends Controller
137 137
     $user = $this->getNewUser($userManager);
138 138
     $form = $this->getRegistrationForm($user);
139 139
     $form->bindRequest($request);
140
+    $errors = $this->checkRegistrationValues($form);
140 141
     
141
-    if ($form->isValid())
142
+    if ($form->isValid() && !count($errors))
142 143
     {
143 144
       $response = $this->getSuccessRegistrationResponse();
144 145
       $userManager->updateUser($user);
@@ -146,7 +147,7 @@ class UserController extends Controller
146 147
       return $response;
147 148
     }
148 149
     
149
-    return $this->getFailureRegistrationResponse($form);
150
+    return $this->getFailureRegistrationResponse($form, $errors);
150 151
   }
151 152
   
152 153
   protected function getRegistrationForm(User $user)
@@ -163,6 +164,7 @@ class UserController extends Controller
163 164
     $user->setPlainPassword($this->generatePassword(32));
164 165
     $user->setEnabled(true);
165 166
     $user->setCguAccepted(true);
167
+    $user->setUsernameUpdatable(true);
166 168
     return $user;
167 169
   }
168 170
   
@@ -188,6 +190,22 @@ class UserController extends Controller
188 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 209
   protected function getSuccessRegistrationResponse()
192 210
   {
193 211
     if (!$this->getRequest()->isXmlHttpRequest())
@@ -201,13 +219,13 @@ class UserController extends Controller
201 219
     ));
202 220
   }
203 221
   
204
-  protected function getFailureRegistrationResponse($form)//, $formHandler)
222
+  protected function getFailureRegistrationResponse($form, $errors = array())//, $formHandler)
205 223
   {
206 224
     $parameters = array(
207 225
       'form'                     => $form->createView(),
208 226
       'error'                    => null,
209 227
       'registration_errors'      => $form->getErrors(),
210
-      //'registration_errors_pers' => $formHandler->getErrors(),
228
+      'registration_errors_pers' => $errors,
211 229
       'last_username'            => null,
212 230
       'registration_page'        => true,
213 231
       'presubscription_form'     => $this->getPreSubscriptionForm()->createView()

+ 7 - 10
src/Muzich/UserBundle/Form/Type/RegistrationFormType.php Bestand weergeven

@@ -10,18 +10,15 @@ class RegistrationFormType  extends AbstractType
10 10
 {
11 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 23
   public function getName()
27 24
   {

+ 3 - 1
src/Muzich/UserBundle/Resources/views/Info/bar.html.twig Bestand weergeven

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