Allow to specify a user by username or email with set-password commannd

This commit is contained in:
Jan Böhmer 2023-02-23 23:39:29 +01:00
parent c831d57614
commit e6d9237bda
2 changed files with 4 additions and 7 deletions

View file

@ -56,7 +56,7 @@ class SetPasswordCommand extends Command
$this
->setDescription('Sets the password of a user')
->setHelp('This password allows you to set the password of a user, without knowing the old password.')
->addArgument('user', InputArgument::REQUIRED, 'The name of the user')
->addArgument('user', InputArgument::REQUIRED, 'The username or email of the user')
;
}
@ -65,17 +65,14 @@ class SetPasswordCommand extends Command
$io = new SymfonyStyle($input, $output);
$user_name = $input->getArgument('user');
/** @var User[] $users */
$users = $this->entityManager->getRepository(User::class)->findBy(['name' => $user_name]);
$user = $this->entityManager->getRepository(User::class)->findByEmailOrName($user_name);
if (empty($users)) {
if (!$user) {
$io->error(sprintf('No user with the given username %s found in the database!', $user_name));
return 1;
}
$user = $users[0];
$io->note('User found!');
if ($user->isSamlUser()) {