|
@@ -11,7 +11,8 @@ use Muzich\CoreBundle\Form\Tag\TagFavoritesForm;
|
11
|
11
|
use Symfony\Component\Validator\Constraints\Email;
|
12
|
12
|
use Symfony\Component\Validator\Constraints\Collection;
|
13
|
13
|
use Symfony\Component\HttpFoundation\Request;
|
14
|
|
-
|
|
14
|
+use Muzich\UserBundle\Form\Type\RegistrationFormType;
|
|
15
|
+use Muzich\CoreBundle\Entity\User;
|
15
|
16
|
|
16
|
17
|
class UserController extends Controller
|
17
|
18
|
{
|
|
@@ -130,8 +131,58 @@ class UserController extends Controller
|
130
|
131
|
;
|
131
|
132
|
}
|
132
|
133
|
|
133
|
|
-
|
134
|
|
- public function registerAction()
|
|
134
|
+ public function registerAction(Request $request)
|
|
135
|
+ {
|
|
136
|
+ $userManager = $this->container->get('fos_user.user_manager');
|
|
137
|
+ $user = $this->getNewUser($userManager);
|
|
138
|
+ $form = $this->createForm(new RegistrationFormType(), $user);
|
|
139
|
+ $form->bindRequest($request);
|
|
140
|
+
|
|
141
|
+ if ($form->isValid())
|
|
142
|
+ {
|
|
143
|
+ $response = $this->getSuccessRegistrationResponse();
|
|
144
|
+ $userManager->updateUser($user);
|
|
145
|
+ $this->authenticateUser($user, $response);
|
|
146
|
+ return $response;
|
|
147
|
+ }
|
|
148
|
+
|
|
149
|
+ return $this->getFailureRegistrationResponse($form);
|
|
150
|
+ }
|
|
151
|
+
|
|
152
|
+ /** @return User */
|
|
153
|
+ protected function getNewUser($userManager)
|
|
154
|
+ {
|
|
155
|
+ $user = $userManager->createUser();
|
|
156
|
+ $user->setUsername($this->generateUsername());
|
|
157
|
+ $user->setPlainPassword($this->generatePassword(32));
|
|
158
|
+ $user->setEnabled(true);
|
|
159
|
+ $user->setCguAccepted(true);
|
|
160
|
+ return $user;
|
|
161
|
+ }
|
|
162
|
+
|
|
163
|
+ protected function generateUsername()
|
|
164
|
+ {
|
|
165
|
+ $qb = $this->getEntityManager()->createQueryBuilder();
|
|
166
|
+ $qb->select('count(id)');
|
|
167
|
+ $qb->from('MuzichCoreBundle:User','id');
|
|
168
|
+ $count = $qb->getQuery()->getSingleScalarResult();
|
|
169
|
+ return 'User'.$count;
|
|
170
|
+ }
|
|
171
|
+
|
|
172
|
+ protected function generatePassword($length = 8)
|
|
173
|
+ {
|
|
174
|
+ $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
175
|
+ $count = mb_strlen($chars);
|
|
176
|
+
|
|
177
|
+ for ($i = 0, $result = ''; $i < $length; $i++) {
|
|
178
|
+ $index = rand(0, $count - 1);
|
|
179
|
+ $result .= mb_substr($chars, $index, 1);
|
|
180
|
+ }
|
|
181
|
+
|
|
182
|
+ return $result;
|
|
183
|
+ }
|
|
184
|
+
|
|
185
|
+ public function registerOldAction()
|
135
|
186
|
{
|
136
|
187
|
$form = $this->container->get('fos_user.registration.form');
|
137
|
188
|
$formHandler = $this->container->get('fos_user.registration.form.handler');
|
|
@@ -180,13 +231,13 @@ class UserController extends Controller
|
180
|
231
|
));
|
181
|
232
|
}
|
182
|
233
|
|
183
|
|
- protected function getFailureRegistrationResponse($form, $formHandler)
|
|
234
|
+ protected function getFailureRegistrationResponse($form)//, $formHandler)
|
184
|
235
|
{
|
185
|
236
|
$parameters = array(
|
186
|
237
|
'form' => $form->createView(),
|
187
|
238
|
'error' => null,
|
188
|
239
|
'registration_errors' => $form->getErrors(),
|
189
|
|
- 'registration_errors_pers' => $formHandler->getErrors(),
|
|
240
|
+ //'registration_errors_pers' => $formHandler->getErrors(),
|
190
|
241
|
'last_username' => null,
|
191
|
242
|
'registration_page' => true,
|
192
|
243
|
'presubscription_form' => $this->getPreSubscriptionForm()->createView()
|