Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / User / LoginUrlCommand.php
index 0b7db7716157bc149b5c50be46e0b526cfc91c1b..f67eb84ee920826da678b3c49bef4fac2b7ab28c 100644 (file)
@@ -10,25 +10,15 @@ namespace Drupal\Console\Command\User;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Command\Command;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
-use Drupal\Console\Core\Style\DrupalStyle;
 
 /**
  * Class UserLoginCommand.
  *
  * @package Drupal\Console
  */
-class LoginUrlCommand extends Command
+class LoginUrlCommand extends UserBase
 {
-    use CommandTrait;
-
-    /**
-     * @var EntityTypeManagerInterface
-     */
-    protected $entityTypeManager;
-
     /**
      * LoginUrlCommand constructor.
      *
@@ -36,8 +26,7 @@ class LoginUrlCommand extends Command
      */
     public function __construct(EntityTypeManagerInterface $entityTypeManager)
     {
-        $this->entityTypeManager = $entityTypeManager;
-        parent::__construct();
+        parent::__construct($entityTypeManager);
     }
 
     /**
@@ -49,41 +38,52 @@ class LoginUrlCommand extends Command
             ->setName('user:login:url')
             ->setDescription($this->trans('commands.user.login.url.description'))
             ->addArgument(
-                'user-id',
+                'user',
                 InputArgument::REQUIRED,
-                $this->trans('commands.user.login.url.options.user-id'),
+                $this->trans('commands.user.login.url.options.user'),
                 null
-            );
+            )
+            ->setAliases(['ulu']);
     }
 
     /**
-   * {@inheritdoc}
-   */
-    protected function execute(InputInterface $input, OutputInterface $output)
+     * {@inheritdoc}
+     */
+    protected function interact(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
+        $this->getUserArgument();
+    }
 
-        $uid = $input->getArgument('user-id');
-        $user = $this->entityTypeManager->getStorage('user')->load($uid);
+    /**
+     * {@inheritdoc}
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $user = $input->getArgument('user');
+        $userEntity = $this->getUserEntity($user);
 
-        if (!$user) {
-            $io->error(
+        if (!$userEntity) {
+            $this->getIo()->error(
                 sprintf(
                     $this->trans('commands.user.login.url.errors.invalid-user'),
-                    $uid
+                    $user
                 )
             );
 
             return 1;
         }
 
-        $url = user_pass_reset_url($user);
-        $io->success(
+        $url = user_pass_reset_url($userEntity) . '/login';
+        $this->getIo()->success(
             sprintf(
                 $this->trans('commands.user.login.url.messages.url'),
-                $user->getUsername(),
-                $url
+                $userEntity->getUsername()
             )
         );
+
+        $this->getIo()->simple($url);
+        $this->getIo()->newLine();
+
+        return 0;
     }
 }