]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Command/ShowUserCommand.php
Merge pull request #4151 from ldidry/fix-4060
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Command / ShowUserCommand.php
CommitLineData
d143fa24
TC
1<?php
2
3namespace Wallabag\CoreBundle\Command;
4
5use Doctrine\ORM\NoResultException;
6use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Output\OutputInterface;
d58199f3 10use Symfony\Component\Console\Style\SymfonyStyle;
d143fa24
TC
11use Wallabag\UserBundle\Entity\User;
12
13class ShowUserCommand extends ContainerAwareCommand
14{
d58199f3
NH
15 /** @var SymfonyStyle */
16 protected $io;
d143fa24
TC
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 {
d58199f3 33 $this->io = new SymfonyStyle($input, $output);
d143fa24
TC
34
35 $username = $input->getArgument('username');
36
37 try {
38 $user = $this->getUser($username);
39 $this->showUser($user);
40 } catch (NoResultException $e) {
d58199f3 41 $this->io->error(sprintf('User "%s" not found.', $username));
d143fa24
TC
42
43 return 1;
44 }
45
46 return 0;
47 }
48
d143fa24
TC
49 private function showUser(User $user)
50 {
d58199f3 51 $this->io->listing([
e1b33efb
NH
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')),
3ef055ce 56 sprintf('Last login: %s', null !== $user->getLastLogin() ? $user->getLastLogin()->format('Y-m-d H:i:s') : 'never'),
a6b242a1
JB
57 sprintf('2FA (email) activated: %s', $user->isEmailTwoFactor() ? 'yes' : 'no'),
58 sprintf('2FA (OTP) activated: %s', $user->isGoogleAuthenticatorEnabled() ? 'yes' : 'no'),
d58199f3 59 ]);
d143fa24
TC
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 {
03ce43d4 71 return $this->getContainer()->get('wallabag_user.user_repository')->findOneByUserName($username);
d143fa24 72 }
d143fa24 73}