2017-06-02 14:53:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wallabag\CoreBundle\Command;
|
|
|
|
|
|
|
|
use Doctrine\ORM\NoResultException;
|
2022-12-15 19:57:02 +00:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
2017-06-02 14:53:03 +00:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2017-07-27 21:25:27 +00:00
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2017-06-02 14:53:03 +00:00
|
|
|
use Wallabag\UserBundle\Entity\User;
|
2022-04-24 14:09:34 +00:00
|
|
|
use Wallabag\UserBundle\Repository\UserRepository;
|
2017-06-02 14:53:03 +00:00
|
|
|
|
2022-12-15 19:57:02 +00:00
|
|
|
class ShowUserCommand extends Command
|
2017-06-02 14:53:03 +00:00
|
|
|
{
|
2022-12-15 19:57:02 +00:00
|
|
|
protected SymfonyStyle $io;
|
|
|
|
private UserRepository $userRepository;
|
|
|
|
|
|
|
|
public function __construct(UserRepository $userRepository)
|
|
|
|
{
|
|
|
|
$this->userRepository = $userRepository;
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
2017-06-02 14:53:03 +00:00
|
|
|
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setName('wallabag:user:show')
|
|
|
|
->setDescription('Show user details')
|
|
|
|
->setHelp('This command shows the details for an user')
|
|
|
|
->addArgument(
|
|
|
|
'username',
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
'User to show details for'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
2017-07-27 21:25:27 +00:00
|
|
|
$this->io = new SymfonyStyle($input, $output);
|
2017-06-02 14:53:03 +00:00
|
|
|
|
|
|
|
$username = $input->getArgument('username');
|
|
|
|
|
|
|
|
try {
|
|
|
|
$user = $this->getUser($username);
|
|
|
|
$this->showUser($user);
|
|
|
|
} catch (NoResultException $e) {
|
2017-07-27 21:25:27 +00:00
|
|
|
$this->io->error(sprintf('User "%s" not found.', $username));
|
2017-06-02 14:53:03 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function showUser(User $user)
|
|
|
|
{
|
2017-07-27 21:25:27 +00:00
|
|
|
$this->io->listing([
|
2017-07-28 22:30:22 +00:00
|
|
|
sprintf('Username: %s', $user->getUsername()),
|
|
|
|
sprintf('Email: %s', $user->getEmail()),
|
|
|
|
sprintf('Display name: %s', $user->getName()),
|
|
|
|
sprintf('Creation date: %s', $user->getCreatedAt()->format('Y-m-d H:i:s')),
|
2017-10-09 14:47:15 +00:00
|
|
|
sprintf('Last login: %s', null !== $user->getLastLogin() ? $user->getLastLogin()->format('Y-m-d H:i:s') : 'never'),
|
2018-12-02 11:43:05 +00:00
|
|
|
sprintf('2FA (email) activated: %s', $user->isEmailTwoFactor() ? 'yes' : 'no'),
|
|
|
|
sprintf('2FA (OTP) activated: %s', $user->isGoogleAuthenticatorEnabled() ? 'yes' : 'no'),
|
2017-07-27 21:25:27 +00:00
|
|
|
]);
|
2017-06-02 14:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches a user from its username.
|
|
|
|
*
|
|
|
|
* @param string $username
|
|
|
|
*
|
2022-08-28 14:59:43 +00:00
|
|
|
* @return User
|
2017-06-02 14:53:03 +00:00
|
|
|
*/
|
|
|
|
private function getUser($username)
|
|
|
|
{
|
2022-12-15 19:57:02 +00:00
|
|
|
return $this->userRepository->findOneByUserName($username);
|
2017-06-02 14:53:03 +00:00
|
|
|
}
|
|
|
|
}
|