addArgument('email', InputArgument::REQUIRED, 'The email of the user'); $this->addOption('password-reset', null, InputOption::VALUE_NONE, 'Whether the user needs to reset the password afterwards'); $this->addOption('all-auth', null, InputOption::VALUE_NONE, 'Ignore that the user is using an external authentication system'); } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $email = $input->getArgument('email'); if ($email === null || $email === '') { $io->error('Need email to create login URL'); return Command::FAILURE; } $user = $this->userRepository->findOneBy(['email' => $email]); if ($user === null) { $io->error('Need username to create login URL'); return Command::FAILURE; } if (!$user->isEnabled()) { $io->error('User is not enabled'); return Command::FAILURE; } if (!$user->isInternalUser() && !$input->getOption('all-auth')) { $io->error('User does not use internal login'); return Command::FAILURE; } $request = new Request(); $request->setLocale($user->getLanguage()); $this->requestStack->push($request); $loginLinkDetails = $this->loginLink->createLoginLink($user, $request); $loginLink = $loginLinkDetails->getUrl(); if ($input->getOption('password-reset') === true) { $user->markPasswordRequested(); $user->setRequiresPasswordReset(true); $this->userRepository->saveUser($user); } $output->writeln($loginLink); return Command::SUCCESS; } }