From f216d814080f426cf092de06ddaf0ca42f4e8028 Mon Sep 17 00:00:00 2001 From: kondou Date: Sat, 24 May 2014 09:49:02 +0200 Subject: Use userManager, color output, return 1 on error --- core/command/resetpassword.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/core/command/resetpassword.php b/core/command/resetpassword.php index 1580bdffa5f..b5184042e35 100644 --- a/core/command/resetpassword.php +++ b/core/command/resetpassword.php @@ -22,12 +22,20 @@ class ResetPassword extends Command { 'user', InputArgument::REQUIRED, 'Username to reset password' - ); + ) ; } protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('user'); + + $userManager = \OC::$server->getUserManager(); + $user = $userManager->get($username); + if (is_null($user)) { + $output->writeln("There is no user called " . $username . ""); + return 1; + } + if ($input->isInteractive()) { /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ $dialog = $this->getHelperSet()->get('dialog'); @@ -36,8 +44,6 @@ class ResetPassword extends Command { 'Enter a new password: ', false ); - /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ - $dialog = $this->getHelperSet()->get('dialog'); $confirm = $dialog->askHiddenResponse( $output, 'Confirm the new password: ', @@ -45,17 +51,20 @@ class ResetPassword extends Command { ); if ($password === $confirm) { - $success = \OC_User::setPassword($username, $password); + $success = $user->setPassword($password); if ($success) { - $output->writeln("Successfully reset password for " . $username); + $output->writeln("Successfully reset password for " . $username . ""); } else { - $output->writeln("There is no user called " . $username); + $output->writeln("Error while resetting password!"); + return 1; } } else { - $output->writeln("Passwords did not match!"); + $output->writeln("Passwords did not match!"); + return 1; } } else { - $output->writeln("Interactive input is needed for entering a new password!"); + $output->writeln("Interactive input is needed for entering a new password!"); + return 1; } } } -- cgit v1.2.3