Exemplo n.º 1
0
 /**
  * Creates a new Usuario entity.
  *
  * @Route("/create", name="security_usuario_create")
  * @Method("POST")
  */
 public function createAction(Request $request)
 {
     $model = new UserModel();
     $form = $this->createCreateForm($model);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $user = new Usuario();
         $user->setUsername($model->getUsername());
         $user->setEmail($model->getEmail());
         $user->setNombres($model->getNombres());
         $user->setApellidos($model->getApellidos());
         $user->setRoles($model->getRoles());
         $user->setPlainPassword($model->getPlainPassword());
         $userManager = $this->get('fos_user.user_manager');
         try {
             $this->get('session')->getFlashBag()->add('success', 'Se ha creado el usuario satisfactoriamente.');
             $userManager->updateUser($user);
             return $this->redirect($this->generateUrl('security_usuario_show', array('id' => $user->getId())));
         } catch (\Exception $e) {
             $this->get('logger')->critical(sprintf('Ha ocurrido un error al crear el usuario. Detalles: %s', $e->getMessage()));
             $this->get('session')->getFlashBag()->add('danger', 'Ha ocurrido un error al crear el usuario.');
         }
     }
     return $this->render('HatueySoftSecurityBundle:Usuario:new.html.twig', array('form' => $form->createView()));
 }
 /**
  * {@inheritDoc}
  */
 public function setUsername($username)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setUsername', array($username));
     return parent::setUsername($username);
 }