1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
public function modifierAction($id)
{
$em = $this->getDoctrine()->getManager();
$utilisateur = $em->getRepository('AcmeUserBundle:User');
$user = $utilisateur ->find($id);
if($user === null)
{
throw $this->createNotFoundException('User [id='.$id.'] inexistant.');
}
$form = $this->createFormBuilder($user)
->add('username', 'text', array('label' => 'Login'))
->add('email', 'email')
->add('password', 'repeated'
, array(
'type' => 'password',
'first_options' => array('label' => 'Nouveau message'),
'second_options' => array('label' => 'Vérification'),
'invalid_message' => 'fos_user.password.mismatch',
))
->add('nom')
->add('prenom')
->add('telephone')
->getForm();
$request = $this->get('request');
if($request->getMethod() == 'POST')
{
$passwordForm =$form->get('password')->getData();
$form->bind($request);
if($form->isValid())
{
$userManager = $this->container->get('fos_user.user_manager');
$user->setPlainPassword($user->getPassword());
$encoder = $this->get('security.encoder_factory')->getEncoder($user);
$password = $encoder->encodePassword($user->getPlainPassword(), $user->getSalt());
$user->setPassword($password);
// echo 'PlainPass : ' . $user->getPlainPassword().'<hr>';
// echo 'Pass : ' .$user->getPassword();
// die;
$userManager->updateUser($user, true);
$this->get('session')
->getFlashBag()
->add('message', 'L\'utilisateur "' . $user->getPrenom() .' ' . $user->getNom() . '" a bien été modifié');
return $this->redirect($this->generateUrl('acmeUser_liste'));
}
}
return $this->render('AcmeUserBundle:Admin:modifierUser.html.twig', array(
'form' => $form->createView(),
'user' => $user
));
} |
Partager