Controller/Auth/PasswordSetController.php
public function createAction(Request $request)
    {
        $form = $this->getSetPasswordForm();
        $form->bind($request);
        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $user = $em->getRepository('Orkestra\Bundle\ApplicationBundle\Entity\User')->find($request->getSession()->get(PasswordSetController::CURRENT_USER_ID_KEY));

            if ($user) {
                $password = $form->get('password')->getData();
                $factory = $this->get('security.encoder_factory');
                $encoder = $factory->getEncoder($user);
                $user->setPassword($encoder->encodePassword($password, $user->getSalt()));

                $em->persist($user);
                $em->flush();
                $this->get('session')->getFlashBag()->set('success', 'Your password has been set.');

                return $this->redirect($this->generateUrl('login'));
            }
        }

        return new JsonErrorResponse('The passwords provided do not match.');
    }
public function createAction(Request $request)
    {
        $form = $this->getSetPasswordForm();
        $form->bind($request);
        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $user = $em->getRepository('Orkestra\Bundle\ApplicationBundle\Entity\User')->find($request->getSession()->get(PasswordSetController::CURRENT_USER_ID_KEY));

            if ($user) {
                $password = $form->get('password')->getData();
                $factory = $this->get('security.encoder_factory');
                $encoder = $factory->getEncoder($user);
                $user->setPassword($encoder->encodePassword($password, $user->getSalt()));

                $em->persist($user);
                $em->flush();
                $this->get('session')->getFlashBag()->set('success', 'Your password has been set.');

                return $this->redirect($this->generateUrl('login'));
            }
        }

        return new JsonErrorResponse('The passwords provided do not match.');
    }
public function createAction ( Request $ request ) { $ form = $ this -> getSetPasswordForm ( ) ; $ form -> bind ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ user = $ em -> getRepository ( 'Orkestra\Bundle\ApplicationBundle\Entity\User' ) -> find ( $ request -> getSession ( ) -> get ( PasswordSetController :: CURRENT_USER_ID_KEY ) ) ; if ( $ user ) { $ password = $ form -> get ( 'password' ) -> getData ( ) ; $ factory = $ this -> get ( 'security.encoder_factory' ) ; $ encoder = $ factory -> getEncoder ( $ user ) ; $ user -> setPassword ( $ encoder -> encodePassword ( $ password , $ user -> getSalt ( ) ) ) ; $ em -> persist ( $ user ) ; $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> set ( 'success' , 'Your password has been set.' ) ; return $ this -> redirect ( $ this -> generateUrl ( 'login' ) ) ; } } return new JsonErrorResponse ( 'The passwords provided do not match.' ) ; }
Resets a user's password and emails them the temporary password

@Route("/set-password", name="orkestra_password_set_create", defaults={"_format"="json"})
@Method("POST")
Resets a user s password and emails them the temporary password