3 namespace Wallabag\CoreBundle\Command
;
5 use Doctrine\ORM\NoResultException
;
6 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
;
7 use Symfony\Component\Console\Input\InputArgument
;
8 use Symfony\Component\Console\Input\InputInterface
;
9 use Symfony\Component\Console\Output\OutputInterface
;
10 use Wallabag\UserBundle\Entity\User
;
12 class ShowUserCommand
extends ContainerAwareCommand
14 /** @var OutputInterface */
17 protected function configure()
20 ->setName('wallabag:user:show')
21 ->setDescription('Show user details')
22 ->setHelp('This command shows the details for an user')
25 InputArgument
::REQUIRED
,
26 'User to show details for'
30 protected function execute(InputInterface
$input, OutputInterface
$output)
32 $this->output
= $output;
34 $username = $input->getArgument('username');
37 $user = $this->getUser($username);
38 $this->showUser($user);
39 } catch (NoResultException
$e) {
40 $output->writeln(sprintf('<error>User "%s" not found.</error>', $username));
51 private function showUser(User
$user)
53 $this->output
->writeln(sprintf('Username : %s', $user->getUsername()));
54 $this->output
->writeln(sprintf('Email : %s', $user->getEmail()));
55 $this->output
->writeln(sprintf('Display name : %s', $user->getName()));
56 $this->output
->writeln(sprintf('Creation date : %s', $user->getCreatedAt()->format('Y-m-d H:i:s')));
57 $this->output
->writeln(sprintf('Last login : %s', $user->getLastLogin() !== null ? $user->getLastLogin()->format('Y-m-d H:i:s') : 'never'));
58 $this->output
->writeln(sprintf('2FA activated: %s', $user->isTwoFactorAuthentication() ? 'yes' : 'no'));
62 * Fetches a user from its username.
64 * @param string $username
66 * @return \Wallabag\UserBundle\Entity\User
68 private function getUser($username)
70 return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username);
73 private function getDoctrine()
75 return $this->getContainer()->get('doctrine');