diff options
author | kondou <kondou@ts.unde.re> | 2014-05-24 09:49:02 +0200 |
---|---|---|
committer | kondou <kondou@ts.unde.re> | 2014-05-24 09:49:02 +0200 |
commit | f216d814080f426cf092de06ddaf0ca42f4e8028 (patch) | |
tree | b5db3c5664a2bad591c019ee03418b77f0e65569 /core/command | |
parent | f75c863257e32b19e7e18be5019a983ac5df8232 (diff) | |
download | nextcloud-server-f216d814080f426cf092de06ddaf0ca42f4e8028.tar.gz nextcloud-server-f216d814080f426cf092de06ddaf0ca42f4e8028.zip |
Use userManager, color output, return 1 on error
Diffstat (limited to 'core/command')
-rw-r--r-- | core/command/resetpassword.php | 25 |
1 files 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("<error>There is no user called " . $username . "</error>"); + 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 { '<question>Enter a new password: </question>', false ); - /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ - $dialog = $this->getHelperSet()->get('dialog'); $confirm = $dialog->askHiddenResponse( $output, '<question>Confirm the new password: </question>', @@ -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("<info>Successfully reset password for " . $username . "</info>"); } else { - $output->writeln("There is no user called " . $username); + $output->writeln("<error>Error while resetting password!</error>"); + return 1; } } else { - $output->writeln("Passwords did not match!"); + $output->writeln("<error>Passwords did not match!</error>"); + return 1; } } else { - $output->writeln("Interactive input is needed for entering a new password!"); + $output->writeln("<error>Interactive input is needed for entering a new password!</error>"); + return 1; } } } |