diff --git a/catalyst/api-bundle/Command/UserCreateCommand.php b/catalyst/api-bundle/Command/UserCreateCommand.php new file mode 100644 index 00000000..13715e65 --- /dev/null +++ b/catalyst/api-bundle/Command/UserCreateCommand.php @@ -0,0 +1,49 @@ +em = $em; + + parent::__construct(); + } + + protected function configure() + { + $this->setName('api:user-create') + ->setDescription('Create new API user.') + ->setHelp('Creates new API user and saves to database.') + ->addArgument('name', InputArgument::REQUIRED, 'name'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $name = $input->getArgument('name'); + + $user = new User(); + $user->setName($name); + + $this->em->persist($user); + $this->em->flush(); + + $output->write('API Key - ' . $user->getAPIKey()); + $output->write('Secret Key - ' . $user->getSecretKey()); + } + + +} diff --git a/config/services.yaml b/config/services.yaml index 93f1f909..b83a0a5e 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -88,3 +88,8 @@ services: Catalyst\APIBundle\Security\APIKeyAuthenticator: arguments: $em: "@doctrine.orm.entity_manager" + + Catalyst\APIBundle\Command\UserCreateCommand: + arguments: + $em: "@doctrine.orm.entity_manager" + tags: ['console.command']