|
@@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraints\Collection;
|
13
|
13
|
use Symfony\Component\HttpFoundation\Request;
|
14
|
14
|
use Muzich\UserBundle\Form\Type\RegistrationFormType;
|
15
|
15
|
use Muzich\CoreBundle\Entity\User;
|
|
16
|
+use Muzich\CoreBundle\Form\User\PasswordForm;
|
16
|
17
|
|
17
|
18
|
class UserController extends Controller
|
18
|
19
|
{
|
|
@@ -107,7 +108,7 @@ class UserController extends Controller
|
107
|
108
|
public function accountAction()
|
108
|
109
|
{
|
109
|
110
|
$user = $this->getUser();
|
110
|
|
- $form_password = $this->container->get('fos_user.change_password.form');
|
|
111
|
+ $form_password = $this->getChangePasswordForm();
|
111
|
112
|
$form_tags_favorites = $this->getTagsFavoritesForm($user);
|
112
|
113
|
$change_email_form = $this->getChangeEmailForm();
|
113
|
114
|
|
|
@@ -123,6 +124,11 @@ class UserController extends Controller
|
123
|
124
|
);
|
124
|
125
|
}
|
125
|
126
|
|
|
127
|
+ protected function getChangePasswordForm()
|
|
128
|
+ {
|
|
129
|
+ return $this->createForm(new PasswordForm(), $this->getUser());
|
|
130
|
+ }
|
|
131
|
+
|
126
|
132
|
protected function getAvatarForm()
|
127
|
133
|
{
|
128
|
134
|
return $this->createFormBuilder($this->getUser())
|
|
@@ -166,6 +172,7 @@ class UserController extends Controller
|
166
|
172
|
$user->setEnabled(true);
|
167
|
173
|
$user->setCguAccepted(true);
|
168
|
174
|
$user->setUsernameUpdatable(true);
|
|
175
|
+ $user->setPasswordSet(false);
|
169
|
176
|
return $user;
|
170
|
177
|
}
|
171
|
178
|
|
|
@@ -280,7 +287,7 @@ class UserController extends Controller
|
280
|
287
|
return $errors;
|
281
|
288
|
}
|
282
|
289
|
|
283
|
|
- public function changePasswordAction()
|
|
290
|
+ public function changePasswordAction(Request $request)
|
284
|
291
|
{
|
285
|
292
|
$user = $this->getUser();
|
286
|
293
|
|
|
@@ -296,40 +303,37 @@ class UserController extends Controller
|
296
|
303
|
)->getSingleResult();
|
297
|
304
|
}
|
298
|
305
|
|
299
|
|
- if (!is_object($user) || !$user instanceof UserInterface) {
|
300
|
|
- throw new AccessDeniedException('This user does not have access to this section.');
|
301
|
|
- }
|
302
|
|
-
|
303
|
|
- $form = $this->container->get('fos_user.change_password.form');
|
304
|
|
- $formHandler = $this->container->get('fos_user.change_password.form.handler');
|
|
306
|
+ $form = $this->getChangePasswordForm();
|
|
307
|
+ $form->bind($request);
|
305
|
308
|
|
306
|
|
- $process = $formHandler->process($user);
|
307
|
|
- if (count(($errors = $this->checkChangePasswordInformations($form))) < 1 && $process)
|
|
309
|
+ if ($form->isValid())
|
308
|
310
|
{
|
|
311
|
+ $userManager = $this->container->get('fos_user.user_manager');
|
|
312
|
+ $userManager->updateUser($form->getData());
|
|
313
|
+ $form->getData()->setPasswordSet(true);
|
|
314
|
+ $this->persist($form->getData());
|
|
315
|
+ $this->flush();
|
309
|
316
|
$this->container->get('session')->setFlash('fos_user_success', 'change_password.flash.success');
|
310
|
|
- return new RedirectResponse($this->generateUrl('my_account'));
|
311
|
|
- }
|
312
|
|
- else
|
313
|
|
- {
|
314
|
|
- $form_tags_favorites = $this->getTagsFavoritesForm($user);
|
315
|
|
- $change_email_form = $this->getChangeEmailForm();
|
316
|
|
-
|
317
|
|
- return $this->container->get('templating')->renderResponse(
|
318
|
|
- 'MuzichUserBundle:User:account.html.twig',
|
319
|
|
- array(
|
320
|
|
- 'form_password' => $form->createView(),
|
321
|
|
- 'errors_pers' => $errors,
|
322
|
|
- 'user' => $user,
|
323
|
|
- 'form_tags_favorites' => $form_tags_favorites->createView(),
|
324
|
|
- 'form_tags_favorites_name' => $form_tags_favorites->getName(),
|
325
|
|
- 'favorite_tags_id' => $this->getTagsFavorites(),
|
326
|
|
- 'change_email_form' => $change_email_form->createView(),
|
327
|
|
- 'avatar_form' => $this->getAvatarForm()->createView()
|
328
|
|
- )
|
329
|
|
- );
|
|
317
|
+ return new RedirectResponse($this->generateUrl('home'));
|
330
|
318
|
}
|
331
|
|
-
|
332
|
319
|
|
|
320
|
+ $form_tags_favorites = $this->getTagsFavoritesForm($user);
|
|
321
|
+ $change_email_form = $this->getChangeEmailForm();
|
|
322
|
+
|
|
323
|
+ return $this->container->get('templating')->renderResponse(
|
|
324
|
+ 'MuzichUserBundle:User:account.html.twig',
|
|
325
|
+ array(
|
|
326
|
+ 'form_password' => $form->createView(),
|
|
327
|
+ 'errors_pers' => array(),
|
|
328
|
+ 'user' => $user,
|
|
329
|
+ 'form_tags_favorites' => $form_tags_favorites->createView(),
|
|
330
|
+ 'form_tags_favorites_name' => $form_tags_favorites->getName(),
|
|
331
|
+ 'favorite_tags_id' => $this->getTagsFavorites(),
|
|
332
|
+ 'change_email_form' => $change_email_form->createView(),
|
|
333
|
+ 'avatar_form' => $this->getAvatarForm()->createView(),
|
|
334
|
+ 'preferences_form' => $this->getPreferencesForm()->createView()
|
|
335
|
+ )
|
|
336
|
+ );
|
333
|
337
|
}
|
334
|
338
|
|
335
|
339
|
/**
|
|
@@ -500,7 +504,7 @@ class UserController extends Controller
|
500
|
504
|
}
|
501
|
505
|
|
502
|
506
|
// En cas d'échec
|
503
|
|
- $form_password = $this->container->get('fos_user.change_password.form');
|
|
507
|
+ $form_password = $this->getChangePasswordForm();
|
504
|
508
|
$form_tags_favorites = $this->getTagsFavoritesForm($user);
|
505
|
509
|
|
506
|
510
|
return $this->container->get('templating')->renderResponse(
|