|
@@ -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()
|