|
3
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the FOSUserBundle package. |
|
|
5 |
* |
|
|
6 |
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace FOS\UserBundle\Command; |
|
|
13 |
|
|
|
14 |
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
|
15 |
use Symfony\Component\Console\Input\InputArgument; |
|
|
16 |
use Symfony\Component\Console\Input\InputInterface; |
|
|
17 |
use Symfony\Component\Console\Output\OutputInterface; |
|
|
18 |
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
|
|
19 |
use FOS\UserBundle\Model\User; |
|
|
20 |
|
|
|
21 |
/** |
|
|
22 |
* @author Antoine Hérault <antoine.herault@gmail.com> |
|
|
23 |
*/ |
|
|
24 |
class ActivateUserCommand extends ContainerAwareCommand |
|
|
25 |
{ |
|
|
26 |
/** |
|
|
27 |
* @see Command |
|
|
28 |
*/ |
|
|
29 |
protected function configure() |
|
|
30 |
{ |
|
|
31 |
$this |
|
|
32 |
->setName('fos:user:activate') |
|
|
33 |
->setDescription('Activate a user') |
|
|
34 |
->setDefinition(array( |
|
|
35 |
new InputArgument('username', InputArgument::REQUIRED, 'The username'), |
|
|
36 |
)) |
|
|
37 |
->setHelp(<<<EOT |
|
|
38 |
The <info>fos:user:activate</info> command activates a user (so they will be able to log in): |
|
|
39 |
|
|
|
40 |
<info>php app/console fos:user:activate matthieu</info> |
|
|
41 |
EOT |
|
|
42 |
); |
|
|
43 |
} |
|
|
44 |
|
|
|
45 |
/** |
|
|
46 |
* @see Command |
|
|
47 |
*/ |
|
|
48 |
protected function execute(InputInterface $input, OutputInterface $output) |
|
|
49 |
{ |
|
|
50 |
$username = $input->getArgument('username'); |
|
|
51 |
|
|
|
52 |
$manipulator = $this->getContainer()->get('fos_user.util.user_manipulator'); |
|
|
53 |
$manipulator->activate($username); |
|
|
54 |
|
|
|
55 |
$output->writeln(sprintf('User "%s" has been activated.', $username)); |
|
|
56 |
} |
|
|
57 |
|
|
|
58 |
/** |
|
|
59 |
* @see Command |
|
|
60 |
*/ |
|
|
61 |
protected function interact(InputInterface $input, OutputInterface $output) |
|
|
62 |
{ |
|
|
63 |
if (!$input->getArgument('username')) { |
|
|
64 |
$username = $this->getHelper('dialog')->askAndValidate( |
|
|
65 |
$output, |
|
|
66 |
'Please choose a username:', |
|
|
67 |
function($username) |
|
|
68 |
{ |
|
|
69 |
if (empty($username)) { |
|
|
70 |
throw new \Exception('Username can not be empty'); |
|
|
71 |
} |
|
|
72 |
return $username; |
|
|
73 |
} |
|
|
74 |
); |
|
|
75 |
$input->setArgument('username', $username); |
|
|
76 |
} |
|
|
77 |
} |
|
|
78 |
} |