Просмотр исходного кода

Evolution #709: Inscription: check de son existance

Bastien Sevajol 11 лет назад
Родитель
Сommit
030a47afed
1 измененных файлов: 18 добавлений и 0 удалений
  1. 18 0
      src/Muzich/UserBundle/Controller/UserController.php

+ 18 - 0
src/Muzich/UserBundle/Controller/UserController.php Просмотреть файл

@@ -156,9 +156,27 @@ class UserController extends Controller
156 156
     $qb->select('count(id)');
157 157
     $qb->from('MuzichCoreBundle:User','id');
158 158
     $count = $qb->getQuery()->getSingleScalarResult();
159
+    
160
+    while ($this->usernameExist($count))
161
+    {
162
+      $count++;
163
+    }
164
+    
159 165
     return 'User'.$count;
160 166
   }
161 167
   
168
+  protected function usernameExist($count)
169
+  {
170
+    $username = 'User'.$count;
171
+    if ($this->getEntityManager()->getRepository('MuzichCoreBundle:User')
172
+      ->findOneByUsername($username))
173
+    {
174
+      return true;
175
+    }
176
+    
177
+    return false;
178
+  }
179
+  
162 180
   protected function generatePassword($length = 8)
163 181
   {
164 182
     $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';