/** * @Route("/mis-datos",name="intranet_myprofile_info") * @Template("MIWIntranetBundle:MyProfile:myInfo.html.twig") */ public function viewMyInfoAction(Request $request) { $user = $this->get('security.context')->getToken()->getUser(); $address = $user->getAddress(); if ($address == null) { $address = new Address(); } // create forms $formUser = $this->createForm(new UserType(), $user); $formAddress = $this->createForm(new AddressType(), $address); $formPassword = $this->createForm(new PasswordType()); if ($request->getMethod() == "POST") { $dm = $this->get('doctrine.odm.mongodb.document_manager'); $formUser->handleRequest($request); $formAddress->handleRequest($request); $formPassword->handleRequest($request); if ($formUser->isValid()) { $user->setName($formUser->get('name')->getData()); $user->setBirthday($formUser->get('birthday')->getData()); $user->setEmail($formUser->get('email')->getData()); $dm->persist($user); $dm->flush(); return $this->redirect($this->generateUrl('intranet_myprofile_info', array('idTab' => 1, 'msgOK' => 'Los datos de usuario han sido guardados satisfactoriamente.'))); } if ($formAddress->isValid()) { $address->setAddress($formAddress->get('address')->getData()); $address->setCommunity($formAddress->get('community')->getData()); $address->setProvince($formAddress->get('province')->getData()); $address->setCity($formAddress->get('city')->getData()); $address->setZipcode($formAddress->get('zipcode')->getData()); $coordinates = new Coordinates(); $coordinates->setX($formAddress->get('coordinates')->get('x')->getData()); $coordinates->setY($formAddress->get('coordinates')->get('y')->getData()); $address->setCoordinates($coordinates); $user->setAddress($address); $dm->persist($user); $dm->flush(); return $this->redirect($this->generateUrl('intranet_myprofile_info', array('idTab' => 2, 'msgOK' => 'Los datos de localizacion han sido guardados satisfactoriamente.'))); } if ($formPassword->isValid()) { $factory = $this->get('security.encoder_factory'); $encoder = $factory->getEncoder($user); $password = $encoder->encodePassword($formPassword->get('passwordNew')->getData(), $user->getSalt()); $user->setPassword($password); $dm->persist($user); $dm->flush(); return $this->redirect($this->generateUrl('intranet_myprofile_info', array('idTab' => 3, 'msgOK' => 'La contraseña han sido modificada satisfactoriamente.'))); } } return array('formUser' => $formUser->createView(), 'formAddress' => $formAddress->createView(), 'formPassword' => $formPassword->createView()); }
public function load(ObjectManager $manager) { print_r("Loading Users\n"); $football = $this->getReference('football'); $paddel = $this->getReference('paddel'); $beisbol = $this->getReference('beisbol'); $basket = $this->getReference('basket'); $volleyball = $this->getReference('voleyball'); $user = new User(); $user->setUsername('alonsus91'); $user->setEmail('*****@*****.**'); $user->setRoles(array('ROLE_USER')); $user->setName('Adrian'); $user->setSports(array($football->getId() => array('level' => 3), $paddel->getId() => array('level' => 1), $beisbol->getId() => array('level' => 5))); $password = '******'; $address = new Address(); $address->setAddress("C\\Perú 22 4º 1"); $address->setCity("Madrid"); $coordinates = new Coordinates(); $coordinates->setX(40.4298909); $coordinates->setY(-3.5406173); $address->setCoordinates($coordinates); $address->setProvince("Madrid"); $encoder = $this->container->get('security.encoder_factory')->getEncoder($user); $cryptedPassword = $encoder->encodePassword($password, $user->getSalt()); $user->setPassword($cryptedPassword); $user->setAddress($address); $user->setEnabled(true); $user2 = new User(); $user2->setUsername('lien'); $user2->setEmail('*****@*****.**'); $user2->setRoles(array('ROLE_USER')); $user2->setName('Lien'); $user2->setSports(array($football->getId() => array('level' => 3), $paddel->getId() => array('level' => 1), $volleyball->getId() => array('level' => 5))); $cryptedPassword2 = $encoder->encodePassword($password, $user2->getSalt()); $user2->setPassword($cryptedPassword2); $user2->setAddress($address); $user2->setEnabled(true); $user3 = new User(); $user3->setUsername('alberto'); $user3->setEmail('*****@*****.**'); $user3->setRoles(array('ROLE_USER')); $user3->setName('Alberto'); $user3->setSports(array($football->getId() => array('position' => 'Defensa', 'level' => 3), $paddel->getId() => array('position' => 'Izquierda', 'level' => 3))); $cryptedPassword3 = $encoder->encodePassword($password, $user3->getSalt()); $user3->setPassword($cryptedPassword3); $user3->setAddress($address); $user3->setEnabled(true); $admin = new User(); $admin->setUsername('admin'); $admin->setEmail('*****@*****.**'); $admin->setRoles(array('ROLE_USER', 'ROLE_ADMIN')); $admin->setName('Administrador'); $cryptedPassword4 = $encoder->encodePassword('admin', $admin->getSalt()); $admin->setPassword($cryptedPassword4); $admin->setEnabled(true); $manager->persist($user); $manager->persist($user2); $manager->persist($user3); $manager->persist($admin); $manager->flush(); $this->addReference('adrian', $user); $this->addReference('lien', $user2); $this->addReference('alberto', $user3); $this->addReference('admin', $admin); }
public function load(ObjectManager $manager) { print_r("Loading Centers\n"); $center = new Center(); $center->setName("Polideportivo Valleaguado"); $center->setDescription("Polideportivo en Coslada"); $address = new Address(); $address->setAddress('Calle del Perú 17'); $address->setZipcode(28823); $address->setCommunity("Comunidad de Madrid"); $address->setProvince("Madrid"); $address->setCity("Coslada"); $coordinates = new Coordinates(); $coordinates->setX(40.4298909); $coordinates->setY(-3.5406173); $address->setCoordinates($coordinates); $center->setAddress($address); $manager->persist($center); $manager->flush(); $center2 = new Center(); $center2->setName("Centro Deportivo Municipal Barajas"); $center2->setDescription("Polideportivo en Barajas"); $address = new Address(); $address->setAddress('Avenida de Logroño 70'); $address->setZipcode(28042); $address->setCommunity("Comunidad de Madrid"); $address->setProvince("Madrid"); $address->setCity("Barajas"); $coordinates = new Coordinates(); $coordinates->setX(40.4595213); $coordinates->setY(-3.5953203, 17); $address->setCoordinates($coordinates); $center2->setAddress($address); $manager->persist($center2); $manager->flush(); $center3 = new Center(); $center3->setName("Centro Deportivo Municipal Entrevías"); $center3->setDescription("Polideportivo en Vallecas"); $address = new Address(); $address->setAddress('Ronda del Sur 4'); $address->setZipcode(28053); $address->setCommunity("Comunidad de Madrid"); $address->setProvince("Madrid"); $address->setCity("Vallecas"); $coordinates = new Coordinates(); $coordinates->setX(40.416598); $coordinates->setY(-3.656455); $address->setCoordinates($coordinates); $center3->setAddress($address); $manager->persist($center3); $manager->flush(); $center4 = new Center(); $center4->setName("Centro Deportivo Municipal La Elipa"); $center4->setDescription("Polideportivo en La Elipa"); $address = new Address(); $address->setAddress('Parque de la Elipa 6'); $address->setZipcode(28030); $address->setCommunity("Comunidad de Madrid"); $address->setProvince("Madrid"); $address->setCity("Moratalaz"); $coordinates = new Coordinates(); $coordinates->setX(40.378417); $coordinates->setY(-3.674526); $address->setCoordinates($coordinates); $center4->setAddress($address); $manager->persist($center4); $manager->flush(); $center5 = new Center(); $center5->setName("Centro Deportivo Municipal Luis Aragonés"); $center5->setDescription("Polideportivo Hortaleza"); $address = new Address(); $address->setAddress('Calle el Provencio 20'); $address->setZipcode(28043); $address->setCommunity("Comunidad de Madrid"); $address->setProvince("Madrid"); $address->setCity("Hortaleza"); $coordinates = new Coordinates(); $coordinates->setX(40.416598); $coordinates->setY(-3.656455); $address->setCoordinates($coordinates); $center5->setAddress($address); $manager->persist($center5); $manager->flush(); $this->addReference('center', $center); $this->addReference('center2', $center2); $this->addReference('center3', $center3); $this->addReference('center4', $center4); $this->addReference('center5', $center5); }