Ejemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $user = new User();
     $user->setUsername("someuser");
     $user->setSalt(md5(uniqid()));
     $encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
     $user->setPassword($encoder->encodePassword('blue', $user->getSalt()));
     $user->setEmail("*****@*****.**");
     $manager->persist($user);
     $manager->flush();
 }
 /**
  * Creates a new User entity.
  *
  * @Route("/register/user", name="user_create")
  * @Method("POST")
  * @Template("SimpleProfileBundle:Security:register.html.twig")
  */
 public function createAction(Request $request)
 {
     $user = new User();
     $em = $this->getDoctrine()->getManager();
     $city = $em->getRepository('SimpleProfileBundle:City')->find($request->request->get('city'));
     $user->setCity($city);
     $form = $this->createForm(new UserType(), $user);
     $form->bind($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
         $user->setPassword($encoder->encodePassword($user->getPassword(), $user->getSalt()));
         $em->persist($user);
         $em->flush();
         return $this->redirect($this->generateUrl('login'));
     }
     $states = $em->getRepository('SimpleProfileBundle:State')->findAll();
     $cities = $em->getRepository('SimpleProfileBundle:City')->getCitiesByState($states[0]->getId());
     return array('states' => $states, 'cities' => $cities, 'form' => $form->createView());
 }