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 Symfony\Component\Console\Style\SymfonyStyle
;
11 use Wallabag\UserBundle\Entity\User
;
13 class ShowUserCommand
extends ContainerAwareCommand
15 /** @var SymfonyStyle */
18 protected function configure()
21 ->setName('wallabag:user:show')
22 ->setDescription('Show user details')
23 ->setHelp('This command shows the details for an user')
26 InputArgument
::REQUIRED
,
27 'User to show details for'
31 protected function execute(InputInterface
$input, OutputInterface
$output)
33 $this->io
= new SymfonyStyle($input, $output);
35 $username = $input->getArgument('username');
38 $user = $this->getUser($username);
39 $this->showUser($user);
40 } catch (NoResultException
$e) {
41 $this->io
->error(sprintf('User "%s" not found.', $username));
49 private function showUser(User
$user)
52 sprintf('Username: %s', $user->getUsername()),
53 sprintf('Email: %s', $user->getEmail()),
54 sprintf('Display name: %s', $user->getName()),
55 sprintf('Creation date: %s', $user->getCreatedAt()->format('Y-m-d H:i:s')),
56 sprintf('Last login: %s', null !== $user->getLastLogin() ? $user->getLastLogin()->format('Y-m-d H:i:s') : 'never'),
57 sprintf('2FA (email) activated: %s', $user->isEmailTwoFactor() ? 'yes' : 'no'),
58 sprintf('2FA (OTP) activated: %s', $user->isGoogleAuthenticatorEnabled() ? 'yes' : 'no'),
63 * Fetches a user from its username.
65 * @param string $username
67 * @return \Wallabag\UserBundle\Entity\User
69 private function getUser($username)
71 return $this->getContainer()->get('wallabag_user.user_repository')->findOneByUserName($username);