Controller/UserController.php
public function updatePasswordAction(Request $request, $id)
    {
        $em = $this->getDoctrine()->getManager();

        $user = $em->getRepository('ChillMainBundle:User')->find($id);

        if (!$user) {
            throw $this->createNotFoundException('Unable to find User entity.');
        }

        $editForm = $this->createEditPasswordForm($user);
        $editForm->handleRequest($request);

        if ($editForm->isValid()) {
            $password = $editForm->getData()->getPassword();
            
            // logging for debug !! WARNING print the new password !!
            $this->get('logger')->debug('update password for an user', 
                    array('method' => __METHOD__, 'password' => $password, 
                        'user' => $user->getUsername()));
            // logging for prod
            $this->get('logger')->info('update password for an user', 
                    array('method' => __METHOD__, 'user' => $user->getUsername()));
            
            $user->setPassword($this->get('security.password_encoder')
                    ->encodePassword($user, $password));
            
            $em->flush();
            
            $this->addFlash('success', $this->get('translator')->trans('Password successfully updated!'));

            return $this->redirect($this->generateUrl('admin_user_edit', array('id' => $id)));
        }

        return $this->render('ChillMainBundle:User:edit_password.html.twig', array(
            'entity'      => $user,
            'edit_form'   => $editForm->createView(),
        ));
    }
public function updatePasswordAction(Request $request, $id)
    {
        $em = $this->getDoctrine()->getManager();

        $user = $em->getRepository('ChillMainBundle:User')->find($id);

        if (!$user) {
            throw $this->createNotFoundException('Unable to find User entity.');
        }

        $editForm = $this->createEditPasswordForm($user);
        $editForm->handleRequest($request);

        if ($editForm->isValid()) {
            $password = $editForm->getData()->getPassword();
            
            // logging for debug !! WARNING print the new password !!
            $this->get('logger')->debug('update password for an user', 
                    array('method' => __METHOD__, 'password' => $password, 
                        'user' => $user->getUsername()));
            // logging for prod
            $this->get('logger')->info('update password for an user', 
                    array('method' => __METHOD__, 'user' => $user->getUsername()));
            
            $user->setPassword($this->get('security.password_encoder')
                    ->encodePassword($user, $password));
            
            $em->flush();
            
            $this->addFlash('success', $this->get('translator')->trans('Password successfully updated!'));

            return $this->redirect($this->generateUrl('admin_user_edit', array('id' => $id)));
        }

        return $this->render('ChillMainBundle:User:edit_password.html.twig', array(
            'entity'      => $user,
            'edit_form'   => $editForm->createView(),
        ));
    }
public function updatePasswordAction ( Request $ request , $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ user = $ em -> getRepository ( 'ChillMainBundle:User' ) -> find ( $ id ) ; if ( ! $ user ) { throw $ this -> createNotFoundException ( 'Unable to find User entity.' ) ; } $ editForm = $ this -> createEditPasswordForm ( $ user ) ; $ editForm -> handleRequest ( $ request ) ; if ( $ editForm -> isValid ( ) ) { $ password = $ editForm -> getData ( ) -> getPassword ( ) ; // logging for debug !! WARNING print the new password !! $ this -> get ( 'logger' ) -> debug ( 'update password for an user' , array ( 'method' => __METHOD__ , 'password' => $ password , 'user' => $ user -> getUsername ( ) ) ) ; // logging for prod $ this -> get ( 'logger' ) -> info ( 'update password for an user' , array ( 'method' => __METHOD__ , 'user' => $ user -> getUsername ( ) ) ) ; $ user -> setPassword ( $ this -> get ( 'security.password_encoder' ) -> encodePassword ( $ user , $ password ) ) ; $ em -> flush ( ) ; $ this -> addFlash ( 'success' , $ this -> get ( 'translator' ) -> trans ( 'Password successfully updated!' ) ) ; return $ this -> redirect ( $ this -> generateUrl ( 'admin_user_edit' , array ( 'id' => $ id ) ) ) ; } return $ this -> render ( 'ChillMainBundle:User:edit_password.html.twig' , array ( 'entity' => $ user , 'edit_form' => $ editForm -> createView ( ) , ) ) ; }
Edits the user password
Edits the user password