Add api:user-create command #164
This commit is contained in:
parent
0d41b46ee9
commit
a2be71a001
2 changed files with 54 additions and 0 deletions
49
catalyst/api-bundle/Command/UserCreateCommand.php
Normal file
49
catalyst/api-bundle/Command/UserCreateCommand.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Catalyst\APIBundle\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use Catalyst\APIBundle\Entity\User;
|
||||
|
||||
class UserCreateCommand extends Command
|
||||
{
|
||||
protected $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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']
|
||||
|
|
|
|||
Loading…
Reference in a new issue