Пример #1
0
 /**
  * @param \Doctrine\Common\Persistence\ObjectManager $em
  */
 public function load(ObjectManager $em)
 {
     $user = new User();
     $user->setUsername('admin');
     $encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
     $encodedPassword = $encoder->encodePassword('admin', $user->getSalt());
     $user->setPassword($encodedPassword);
     $em->persist($user);
     $em->flush();
 }
Пример #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = $input->getArgument('username');
     $password = $input->getArgument('password');
     $em = $this->getContainer()->get('doctrine')->getEntityManager();
     $user = new User();
     $user->setUsername($username);
     // encode the password
     $factory = $this->getContainer()->get('security.encoder_factory');
     $encoder = $factory->getEncoder($user);
     $encodedPassword = $encoder->encodePassword($password, $user->getSalt());
     $user->setPassword($encodedPassword);
     $em->persist($user);
     $em->flush();
     $output->writeln(sprintf('Added %s user with password %s', $username, $password));
 }