From 011bd0a1c47e32fb9df9fdd63524d24b04a7ae14 Mon Sep 17 00:00:00 2001 From: kondou Date: Mon, 12 May 2014 15:33:26 +0200 Subject: [PATCH 1/8] Add a resetadminpass command to console - fix #8248 --- core/command/resetadminpass.php | 36 +++++++++++++++++++++++++++++++++ core/register_command.php | 1 + 2 files changed, 37 insertions(+) create mode 100644 core/command/resetadminpass.php diff --git a/core/command/resetadminpass.php b/core/command/resetadminpass.php new file mode 100644 index 0000000000..6f42801061 --- /dev/null +++ b/core/command/resetadminpass.php @@ -0,0 +1,36 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Core\Command; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Output\OutputInterface; + +class ResetAdminPass extends Command { + protected function configure() { + $this + ->setName('resetadminpass') + ->setDescription('Resets the password of the first user') + ->addArgument( + 'password', + InputArgument::REQUIRED, + 'Password to reset to' + ); + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $password = $input->getArgument('password'); + $query = \OC_DB::prepare('SELECT `uid` FROM `*PREFIX*users` LIMIT 1'); + $username = $query->execute()->fetchOne(); + \OC_User::setPassword($username, $password); + $output->writeln("Successfully reset password for " . $username . " to " . $password); + } +} diff --git a/core/register_command.php b/core/register_command.php index 2efa838e9e..ef5456a1bd 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -10,6 +10,7 @@ $application->add(new OC\Core\Command\Status); $application->add(new OC\Core\Command\Db\GenerateChangeScript()); $application->add(new OC\Core\Command\Upgrade()); +$application->add(new OC\Core\Command\ResetAdminPass()); $application->add(new OC\Core\Command\Maintenance\SingleUser()); $application->add(new OC\Core\Command\App\Disable()); $application->add(new OC\Core\Command\App\Enable()); From e5e77b370a64c8e391d64a2924f49feee284eac2 Mon Sep 17 00:00:00 2001 From: kondou Date: Mon, 12 May 2014 16:10:59 +0200 Subject: [PATCH 2/8] Make ResetAdminPass to ResetPassword --- core/command/resetadminpass.php | 36 ----------------------- core/command/resetpassword.php | 52 +++++++++++++++++++++++++++++++++ core/register_command.php | 2 +- 3 files changed, 53 insertions(+), 37 deletions(-) delete mode 100644 core/command/resetadminpass.php create mode 100644 core/command/resetpassword.php diff --git a/core/command/resetadminpass.php b/core/command/resetadminpass.php deleted file mode 100644 index 6f42801061..0000000000 --- a/core/command/resetadminpass.php +++ /dev/null @@ -1,36 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace OC\Core\Command; - -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Output\OutputInterface; - -class ResetAdminPass extends Command { - protected function configure() { - $this - ->setName('resetadminpass') - ->setDescription('Resets the password of the first user') - ->addArgument( - 'password', - InputArgument::REQUIRED, - 'Password to reset to' - ); - ; - } - - protected function execute(InputInterface $input, OutputInterface $output) { - $password = $input->getArgument('password'); - $query = \OC_DB::prepare('SELECT `uid` FROM `*PREFIX*users` LIMIT 1'); - $username = $query->execute()->fetchOne(); - \OC_User::setPassword($username, $password); - $output->writeln("Successfully reset password for " . $username . " to " . $password); - } -} diff --git a/core/command/resetpassword.php b/core/command/resetpassword.php new file mode 100644 index 0000000000..fa91d0a73a --- /dev/null +++ b/core/command/resetpassword.php @@ -0,0 +1,52 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Core\Command; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Output\OutputInterface; + +class ResetPassword extends Command { + protected function configure() { + $this + ->setName('resetpassword') + ->setDescription('Resets the password of the named user') + ->addArgument( + 'user', + InputArgument::REQUIRED, + 'Username to reset password' + ); + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $username = $input->getArgument('user'); + if ($input->isInteractive()) { + $dialog = $this->getHelperSet()->get('dialog'); + $password = $dialog->askHiddenResponse( + $output, + 'Enter a new password: ', + false + ); + $dialog = $this->getHelperSet()->get('dialog'); + $confirm = $dialog->askHiddenResponse( + $output, + 'Confirm the new password: ', + false + ); + } + if ($password === $confirm) { + \OC_User::setPassword($username, $password); + $output->writeln("Successfully reset password for " . $username); + } else { + $output->writeln("Passwords did not match!"); + } + } +} diff --git a/core/register_command.php b/core/register_command.php index ef5456a1bd..44d7dbccba 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -10,7 +10,7 @@ $application->add(new OC\Core\Command\Status); $application->add(new OC\Core\Command\Db\GenerateChangeScript()); $application->add(new OC\Core\Command\Upgrade()); -$application->add(new OC\Core\Command\ResetAdminPass()); +$application->add(new OC\Core\Command\ResetPassword()); $application->add(new OC\Core\Command\Maintenance\SingleUser()); $application->add(new OC\Core\Command\App\Disable()); $application->add(new OC\Core\Command\App\Enable()); From 2a5e1a188508b66f8b4e363382c3f789c3adc1a4 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 12 May 2014 20:05:52 +0200 Subject: [PATCH 3/8] Back to the future --- core/command/resetpassword.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/command/resetpassword.php b/core/command/resetpassword.php index fa91d0a73a..1dca7c5ee8 100644 --- a/core/command/resetpassword.php +++ b/core/command/resetpassword.php @@ -1,6 +1,6 @@ + * Copyright (c) 2014 Christopher Schäpers * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. From f75c863257e32b19e7e18be5019a983ac5df8232 Mon Sep 17 00:00:00 2001 From: kondou Date: Tue, 13 May 2014 15:56:25 +0200 Subject: [PATCH 4/8] Add doc, check return-value, fix spacing, require interactive --- core/command/resetpassword.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/core/command/resetpassword.php b/core/command/resetpassword.php index 1dca7c5ee8..1580bdffa5 100644 --- a/core/command/resetpassword.php +++ b/core/command/resetpassword.php @@ -29,24 +29,33 @@ class ResetPassword extends Command { protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('user'); if ($input->isInteractive()) { + /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ $dialog = $this->getHelperSet()->get('dialog'); $password = $dialog->askHiddenResponse( $output, '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: ', + 'Confirm the new password: ', false ); - } - if ($password === $confirm) { - \OC_User::setPassword($username, $password); - $output->writeln("Successfully reset password for " . $username); + + if ($password === $confirm) { + $success = \OC_User::setPassword($username, $password); + if ($success) { + $output->writeln("Successfully reset password for " . $username); + } else { + $output->writeln("There is no user called " . $username); + } + } else { + $output->writeln("Passwords did not match!"); + } } else { - $output->writeln("Passwords did not match!"); + $output->writeln("Interactive input is needed for entering a new password!"); } } } From f216d814080f426cf092de06ddaf0ca42f4e8028 Mon Sep 17 00:00:00 2001 From: kondou Date: Sat, 24 May 2014 09:49:02 +0200 Subject: [PATCH 5/8] 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 1580bdffa5..b5184042e3 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; } } } From 52e7bf96306a048c43d77d5c3db42f89187f45ce Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 28 May 2014 22:42:33 +0200 Subject: [PATCH 6/8] Receive \OC\User\Manager as a constructor dependency. --- core/command/resetpassword.php | 12 ++++++++++-- core/register_command.php | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/core/command/resetpassword.php b/core/command/resetpassword.php index b5184042e3..ab877655e2 100644 --- a/core/command/resetpassword.php +++ b/core/command/resetpassword.php @@ -14,6 +14,15 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; class ResetPassword extends Command { + + /** @var \OC\User\Manager */ + protected $userManager; + + public function __construct(\OC\User\Manager $userManager) { + $this->userManager = $userManager; + parent::__construct(); + } + protected function configure() { $this ->setName('resetpassword') @@ -29,8 +38,7 @@ class ResetPassword extends Command { protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('user'); - $userManager = \OC::$server->getUserManager(); - $user = $userManager->get($username); + $user = $this->userManager->get($username); if (is_null($user)) { $output->writeln("There is no user called " . $username . ""); return 1; diff --git a/core/register_command.php b/core/register_command.php index 44d7dbccba..e9b6250888 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -10,7 +10,7 @@ $application->add(new OC\Core\Command\Status); $application->add(new OC\Core\Command\Db\GenerateChangeScript()); $application->add(new OC\Core\Command\Upgrade()); -$application->add(new OC\Core\Command\ResetPassword()); +$application->add(new OC\Core\Command\ResetPassword(\OC::$server->getUserManager())); $application->add(new OC\Core\Command\Maintenance\SingleUser()); $application->add(new OC\Core\Command\App\Disable()); $application->add(new OC\Core\Command\App\Enable()); From 8981929e92b9dc22e6542f16dc1cbce7cc338a9f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 28 May 2014 22:48:35 +0200 Subject: [PATCH 7/8] Document type of user project. --- core/command/resetpassword.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/command/resetpassword.php b/core/command/resetpassword.php index ab877655e2..ddff7a980d 100644 --- a/core/command/resetpassword.php +++ b/core/command/resetpassword.php @@ -38,6 +38,7 @@ class ResetPassword extends Command { protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('user'); + /** @var $user \OC\User\User */ $user = $this->userManager->get($username); if (is_null($user)) { $output->writeln("There is no user called " . $username . ""); From f81ee94cad8a997c3a2fef0b6aac4f8d509571f6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 28 May 2014 22:53:44 +0200 Subject: [PATCH 8/8] Move resetpassword into user: command space. --- core/command/{ => user}/resetpassword.php | 4 ++-- core/register_command.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename core/command/{ => user}/resetpassword.php (96%) diff --git a/core/command/resetpassword.php b/core/command/user/resetpassword.php similarity index 96% rename from core/command/resetpassword.php rename to core/command/user/resetpassword.php index ddff7a980d..d7893c291e 100644 --- a/core/command/resetpassword.php +++ b/core/command/user/resetpassword.php @@ -6,7 +6,7 @@ * See the COPYING-README file. */ -namespace OC\Core\Command; +namespace OC\Core\Command\User; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -25,7 +25,7 @@ class ResetPassword extends Command { protected function configure() { $this - ->setName('resetpassword') + ->setName('user:resetpassword') ->setDescription('Resets the password of the named user') ->addArgument( 'user', diff --git a/core/register_command.php b/core/register_command.php index e9b6250888..8efd2673af 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -10,10 +10,10 @@ $application->add(new OC\Core\Command\Status); $application->add(new OC\Core\Command\Db\GenerateChangeScript()); $application->add(new OC\Core\Command\Upgrade()); -$application->add(new OC\Core\Command\ResetPassword(\OC::$server->getUserManager())); $application->add(new OC\Core\Command\Maintenance\SingleUser()); $application->add(new OC\Core\Command\App\Disable()); $application->add(new OC\Core\Command\App\Enable()); $application->add(new OC\Core\Command\App\ListApps()); $application->add(new OC\Core\Command\Maintenance\Repair(new \OC\Repair())); $application->add(new OC\Core\Command\User\Report()); +$application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager()));