Guest User

Untitled

a guest
Sep 25th, 2016
57
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function editAction(Request $request, User $user)
  2. {
  3. $password = $user->getPassword();
  4.  
  5. $deleteForm = $this->createDeleteForm($user);
  6. $editForm = $this->createForm('UserBundleFormEditUserType', $user);
  7. $editForm->handleRequest($request);
  8.  
  9.  
  10. if ($editForm->isSubmitted() && $editForm->isValid()) {
  11.  
  12. if(!empty($form->get('password')->getData())){
  13. $user->setPlainPassword($form->get('password')->getData());
  14. }
  15. else{
  16. $user->setPassword($password);
  17. }
  18. $em = $this->getDoctrine()->getManager();
  19. $em->persist($user);
  20. $em->flush();
  21.  
  22. return $this->redirectToRoute('user_edit', array('id' => $user->getId()));
  23. }
  24.  
  25. return $this->render('UserBundle:user:edit.html.twig', array(
  26. 'user' => $user,
  27. 'edit_form' => $editForm->createView(),
  28. 'delete_form' => $deleteForm->createView(),
  29. ));
  30. }
  31.  
  32. public function buildForm(FormBuilderInterface $builder, array $options)
  33. {
  34. $builder
  35. ->add('nom')
  36. ->add('prenom')
  37. ->add('username')
  38. ->add('email')
  39. ->add('password', 'repeated',
  40. array(
  41. 'type' => 'password',
  42. 'invalid_message' => 'Les mots de passes doivent être identique',
  43. 'required' => false,
  44. 'first_options' => array('label' => 'Nouveau mot de passe'),
  45. 'second_options' => array('label' => 'Confirmation du mot de passe')
  46. )
  47. )
  48. ->add('enabled')
  49. ->add('last_login')
  50. ;
  51. }
RAW Paste Data