0

i am trying to edit my user, and i get no errors when i submit, but the user is not updated in the DB.

i was wondering that, if the admin make some changes in the user(the other fields, not password), it will persist the user with the old password, and if the admin change password, it will persist the newest password :D

sorry for my english and thank you guys :)

this is my EditAction in \UserController.php

public function editAction(Request $request, User $user)
{                  
    $password = $user->getPassword();

    $deleteForm = $this->createDeleteForm($user);
    $editForm = $this->createForm('UserBundle\Form\EditUserType', $user);
    $editForm->handleRequest($request);


    if ($editForm->isSubmitted() && $editForm->isValid()) {

        if(!empty($form->get('password')->getData())){
            $user->setPlainPassword($form->get('password')->getData());
            }
        else{
        $user->setPassword($password);
            }              
        $em = $this->getDoctrine()->getManager();
        $em->persist($user);
        $em->flush();

        return $this->redirectToRoute('user_edit', array('id' => $user->getId()));
    }

    return $this->render('UserBundle:user:edit.html.twig', array(
        'user' => $user,
        'edit_form' => $editForm->createView(),
        'delete_form' => $deleteForm->createView(),
    ));
}

and this is my form \EditUserType.php

    public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('nom')
        ->add('prenom')    
        ->add('username') 
        ->add('email')
        ->add('password', 'repeated',
        array(
            'type' => 'password',
            'invalid_message' => 'Les mots de passes doivent être identique',
            'required' => false,
            'first_options'  => array('label' => 'Nouveau mot de passe'),
            'second_options' => array('label' => 'Confirmation du mot de passe')
        )
        )                
        ->add('enabled')
        ->add('last_login')
    ;
}
zlot
  • 41
  • 4

1 Answers1

0

You have to use FosUserBundle Manager service, according to this : Fos User Manager Service.

Community
  • 1
  • 1