]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Command/ShowUserCommand.php
Merge pull request #4151 from ldidry/fix-4060
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Command / ShowUserCommand.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Command;
4
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;
12
13 class ShowUserCommand extends ContainerAwareCommand
14 {
15 /** @var SymfonyStyle */
16 protected $io;
17
18 protected function configure()
19 {
20 $this
21 ->setName('wallabag:user:show')
22 ->setDescription('Show user details')
23 ->setHelp('This command shows the details for an user')
24 ->addArgument(
25 'username',
26 InputArgument::REQUIRED,
27 'User to show details for'
28 );
29 }
30
31 protected function execute(InputInterface $input, OutputInterface $output)
32 {
33 $this->io = new SymfonyStyle($input, $output);
34
35 $username = $input->getArgument('username');
36
37 try {
38 $user = $this->getUser($username);
39 $this->showUser($user);
40 } catch (NoResultException $e) {
41 $this->io->error(sprintf('User "%s" not found.', $username));
42
43 return 1;
44 }
45
46 return 0;
47 }
48
49 private function showUser(User $user)
50 {
51 $this->io->listing([
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'),
59 ]);
60 }
61
62 /**
63 * Fetches a user from its username.
64 *
65 * @param string $username
66 *
67 * @return \Wallabag\UserBundle\Entity\User
68 */
69 private function getUser($username)
70 {
71 return $this->getContainer()->get('wallabag_user.user_repository')->findOneByUserName($username);
72 }
73 }