Exemple #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();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = $input->getArgument('username');
     $password = $input->getArgument('password');
     $em = $this->getContainer()->get('doctrine')->getManager();
     $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));
 }
Exemple #3
0
 public function equals(User $user)
 {
     return $user->getUsername() == $this->getUsername();
 }