f67eb84ee920826da678b3c49bef4fac2b7ab28c
[yaffs-website] / vendor / drupal / console / src / Command / User / LoginUrlCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains Drupal\Console\Command\User\LoginUrlCommand.
6  */
7
8 namespace Drupal\Console\Command\User;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputArgument;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Drupal\Core\Entity\EntityTypeManagerInterface;
14
15 /**
16  * Class UserLoginCommand.
17  *
18  * @package Drupal\Console
19  */
20 class LoginUrlCommand extends UserBase
21 {
22     /**
23      * LoginUrlCommand constructor.
24      *
25      * @param EntityTypeManagerInterface $entityTypeManager
26      */
27     public function __construct(EntityTypeManagerInterface $entityTypeManager)
28     {
29         parent::__construct($entityTypeManager);
30     }
31
32     /**
33      * {@inheritdoc}
34      */
35     protected function configure()
36     {
37         $this
38             ->setName('user:login:url')
39             ->setDescription($this->trans('commands.user.login.url.description'))
40             ->addArgument(
41                 'user',
42                 InputArgument::REQUIRED,
43                 $this->trans('commands.user.login.url.options.user'),
44                 null
45             )
46             ->setAliases(['ulu']);
47     }
48
49     /**
50      * {@inheritdoc}
51      */
52     protected function interact(InputInterface $input, OutputInterface $output)
53     {
54         $this->getUserArgument();
55     }
56
57     /**
58      * {@inheritdoc}
59      */
60     protected function execute(InputInterface $input, OutputInterface $output)
61     {
62         $user = $input->getArgument('user');
63         $userEntity = $this->getUserEntity($user);
64
65         if (!$userEntity) {
66             $this->getIo()->error(
67                 sprintf(
68                     $this->trans('commands.user.login.url.errors.invalid-user'),
69                     $user
70                 )
71             );
72
73             return 1;
74         }
75
76         $url = user_pass_reset_url($userEntity) . '/login';
77         $this->getIo()->success(
78             sprintf(
79                 $this->trans('commands.user.login.url.messages.url'),
80                 $userEntity->getUsername()
81             )
82         );
83
84         $this->getIo()->simple($url);
85         $this->getIo()->newLine();
86
87         return 0;
88     }
89 }