Пример #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getHelperSet()->get('dialog');
     $password = $dialog->askHiddenResponse($output, 'Password: '******'name'));
     $user->setEmail($input->getOption('email'));
     $user->setPassword($password);
     $user->setRole($input->getOption('admin') ? 1 : 0);
     $em = $this->getContainer()->get('doctrine')->getManager();
     $em->persist($user);
     $em->persist($setting);
     $em->flush();
     $output->writeln('User created');
 }
Пример #2
0
 /**
  * @Security("has_role('ROLE_ADMIN')")
  */
 public function addAction()
 {
     /* Handle form. */
     $user = new User();
     $setting = new Setting();
     $setting->setUser($user);
     $form = $this->createForm(new UserType(), $user, array('validation_groups' => array('Default', 'add')));
     $form->handleRequest($this->get('request'));
     /* Insert and redirect or show the form. */
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($user);
         $em->persist($setting);
         $em->flush();
         $this->get('session')->getFlashBag()->add('info', 'The user was added.');
         return $this->redirect($this->generateUrl('swd_analyzer_users_list'));
     } else {
         return $this->render('SwdAnalyzerBundle:User:show.html.twig', array('form' => $form->createView()));
     }
 }