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 $this
->setDescription('Sets the password of a user') ->setDescription('Sets the password of a user')
->setHelp('This password allows you to set the password of a user, without knowing the old password.') ->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); $io = new SymfonyStyle($input, $output);
$user_name = $input->getArgument('user'); $user_name = $input->getArgument('user');
/** @var User[] $users */ $user = $this->entityManager->getRepository(User::class)->findByEmailOrName($user_name);
$users = $this->entityManager->getRepository(User::class)->findBy(['name' => $user_name]);
if (empty($users)) { if (!$user) {
$io->error(sprintf('No user with the given username %s found in the database!', $user_name)); $io->error(sprintf('No user with the given username %s found in the database!', $user_name));
return 1; return 1;
} }
$user = $users[0];
$io->note('User found!'); $io->note('User found!');
if ($user->isSamlUser()) { if ($user->isSamlUser()) {

View file

@ -57,7 +57,7 @@ class UsersPermissionsCommand extends Command
protected function configure(): void protected function configure(): void
{ {
$this $this
->addArgument('user', InputArgument::REQUIRED, 'The username of the user to view') ->addArgument('user', InputArgument::REQUIRED, 'The username or email of the user to view')
->addOption('noInherit', null, InputOption::VALUE_NONE, 'Do not inherit permissions from groups') ->addOption('noInherit', null, InputOption::VALUE_NONE, 'Do not inherit permissions from groups')
->addOption('edit', '', InputOption::VALUE_NONE, 'Edit the permissions of the user') ->addOption('edit', '', InputOption::VALUE_NONE, 'Edit the permissions of the user')
; ;