aboutsummaryrefslogtreecommitdiff
path: root/cli/Commands
diff options
context:
space:
mode:
authorMarcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>2024-10-23 05:02:17 +0000
committerMarcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>2024-10-23 05:02:17 +0000
commitfebf8a5f18a558e8d1a0ec4c748d348de726fcf4 (patch)
tree482f6412abdaf24aff21210989b2c8a9c7727e47 /cli/Commands
parent5974e61b65c86eba9c3d5430bebd3762583b3962 (diff)
Add `--confirmation`/`--no-confirmation` to read password from stdin.
Closes #3910 Merge request studip/studip!2766
Diffstat (limited to 'cli/Commands')
-rw-r--r--cli/Commands/User/ChangePassword.php38
1 files changed, 26 insertions, 12 deletions
diff --git a/cli/Commands/User/ChangePassword.php b/cli/Commands/User/ChangePassword.php
index f9763f9..00de33f 100644
--- a/cli/Commands/User/ChangePassword.php
+++ b/cli/Commands/User/ChangePassword.php
@@ -29,6 +29,13 @@ class ChangePassword extends Command
InputArgument::REQUIRED,
'The username of the user whose password will be changed.'
);
+ $this->addOption(
+ 'confirmation',
+ null,
+ InputOption::VALUE_NEGATABLE,
+ 'Enter password twice to confirm it',
+ true
+ );
}
protected function execute(InputInterface $input, OutputInterface $output)
@@ -41,24 +48,33 @@ class ChangePassword extends Command
return Command::FAILURE;
}
+ $passwords = $this->askPassword($input, $output);
+ $status = $this->changePassword($user, ...$passwords);
+ if (isset($status)) {
+ $output->writeln('<error>' . $status . '</error>');
+
+ return Command::FAILURE;
+ }
+
+ return Command::SUCCESS;
+ }
+
+ /**
+ * @return array{string,string} a pair of strings containing the password and its confirmation
+ */
+ private function askPassword(InputInterface $input, OutputInterface $output): array
+ {
$helper = $this->getHelper('question');
$question = new Question('New password: ', '');
$question->setHidden(true);
- $password = $helper->ask($input, $output, $question);
-
$question2 = new Question('Re-type password: ', '');
$question2->setHidden(true);
- $password2 = $helper->ask($input, $output, $question2);
-
- $status = $this->changePassword($user, $password, $password2);
- if (isset($status)) {
- $output->writeln('<error>' . $status . '</error>');
- return Command::FAILURE;
- }
+ $password = $helper->ask($input, $output, $question);
+ $password2 = $input->getOption('confirmation') ? $helper->ask($input, $output, $question2) : $password;
- return Command::SUCCESS;
+ return [$password, $password2];
}
private function changePassword(\User $user, string $password, string $password2): ?string
@@ -88,8 +104,6 @@ class ChangePassword extends Command
return 'The password could not be set.';
}
- StudipLog::USER_NEWPWD($user->id, null, 'Passwort neu gesetzt', null, $user->id);
-
return null;
}
}