|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DoS\UserBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Sylius\Bundle\UserBundle\Command\CreateUserCommand as BaseCreateUserCommand; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
class CreateUserCommand extends BaseCreateUserCommand |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* {@inheritdoc} |
|
15
|
|
|
*/ |
|
16
|
|
|
protected function configure() |
|
17
|
|
|
{ |
|
18
|
|
|
$this |
|
19
|
|
|
->setName('dos:user:create') |
|
20
|
|
|
->setDescription('Creates a new user account.') |
|
21
|
|
|
->setDefinition(array( |
|
22
|
|
|
new InputArgument('email', InputArgument::REQUIRED, 'Email'), |
|
23
|
|
|
new InputArgument('password', InputArgument::REQUIRED, 'Password'), |
|
24
|
|
|
new InputArgument('roles', InputArgument::IS_ARRAY, 'RBAC roles'), |
|
25
|
|
|
new InputOption('disabled', null, InputOption::VALUE_NONE, 'Set the user as a disabled user'), |
|
26
|
|
|
)) |
|
27
|
|
|
->setHelp(<<<EOT |
|
28
|
|
|
The <info>%command.name%</info> command creates a new user account. |
|
29
|
|
|
EOT |
|
30
|
|
|
) |
|
31
|
|
|
; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
38
|
|
|
{ |
|
39
|
|
|
$email = $input->getArgument('email'); |
|
40
|
|
|
$password = $input->getArgument('password'); |
|
41
|
|
|
$roles = $input->getArgument('roles'); |
|
42
|
|
|
$disabled = $input->getOption('disabled'); |
|
43
|
|
|
|
|
44
|
|
|
$securityRoles = ['ROLE_USER']; |
|
45
|
|
|
|
|
46
|
|
|
if (!empty($roles)) { |
|
47
|
|
|
$securityRoles = array_merge($securityRoles, $roles); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$user = $this->createUser( |
|
51
|
|
|
$email, |
|
52
|
|
|
$password, |
|
53
|
|
|
!$disabled, |
|
54
|
|
|
array(), |
|
55
|
|
|
$securityRoles |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
$this->getEntityManager()->persist($user); |
|
59
|
|
|
$this->getEntityManager()->flush(); |
|
60
|
|
|
|
|
61
|
|
|
$output->writeln(sprintf('Created user <comment>%s</comment>', $email)); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|