Esempio n. 1
0
 /**
  * function that can be called to create a new user.
  *
  * @param TokenInterface $token
  *
  * @inheritDoc
  *
  * @return mixed|UserInterface
  */
 public function createUser(TokenInterface $token)
 {
     $newUser = new User();
     $newUser->setUsername($token->getUsername());
     $newUser->setRoles($token->getRoles());
     $em = $this->getEntityManager();
     $em->persist($newUser);
     $em->flush();
     return $newUser;
 }
Esempio n. 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $createOrUpdated = 'updated';
     $username = $input->getArgument('username');
     $password = $input->getArgument('password') ? $input->getArgument('password') : self::randomPassword();
     // check if user exists
     $repo = $this->getContainer()->get('doctrine')->getRepository('UBCExamMainBundle:User');
     $user = $repo->findOneByUsername($username);
     if (!$user) {
         $user = new User();
         $createOrUpdated = 'created';
     }
     $user->setUsername($username);
     $user->setPassword($password);
     $user->setRoleString($input->getArgument('role'));
     $em = $this->getContainer()->get('doctrine')->getManager();
     $em->persist($user);
     $em->flush();
     $passwordMsg = $input->getArgument('password') ? '' : " with password '{$password}'";
     $output->writeln("User {$username} has been {$createOrUpdated} successfully{$passwordMsg}.");
 }