/**
  * {@InheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = $input->getArgument('username');
     $password = $input->getArgument('password');
     try {
         $createdUser = $this->api->createUser($username, $password);
     } catch (\Doctrine\DBAL\Exception\UniqueConstraintViolationException $e) {
         $output->writeln('Oops, an user ' . $username . ' already exists.');
         return;
     }
     $output->writeln('User ' . $username . ' has been created.');
     $output->writeln('Full player data:');
     $output->writeln(print_r($createdUser, true));
 }
Exemple #2
0
 /**
  * Create or update an User.
  * Should be run by logged user or admin.
  *
  * @param Request $request
  *
  * @return ApiResponse
  */
 public function postUser(Request $request)
 {
     $username = $request->request->get('username');
     $password = $request->request->get('password');
     if (empty($username)) {
         throw new BadRequestHttpException('Username cannot be empty.');
     }
     if (empty($password)) {
         throw new BadRequestHttpException('Password cannot be empty.');
     }
     try {
         $user = $this->api->createUser($username, $password);
     } catch (UserAlreadyExistsException $e) {
         throw new ConflictHttpException('An user with username "' . $username . '" already exists.', $e);
     }
     return new ApiResponse($user, Response::HTTP_CREATED);
 }