From 011bd0a1c47e32fb9df9fdd63524d24b04a7ae14 Mon Sep 17 00:00:00 2001 From: kondou Date: Mon, 12 May 2014 15:33:26 +0200 Subject: Add a resetadminpass command to console - fix #8248 --- core/register_command.php | 1 + 1 file changed, 1 insertion(+) (limited to 'core/register_command.php') diff --git a/core/register_command.php b/core/register_command.php index 2efa838e9ee..ef5456a1bd1 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()); -- cgit v1.2.3 From e5e77b370a64c8e391d64a2924f49feee284eac2 Mon Sep 17 00:00:00 2001 From: kondou Date: Mon, 12 May 2014 16:10:59 +0200 Subject: 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 (limited to 'core/register_command.php') diff --git a/core/command/resetadminpass.php b/core/command/resetadminpass.php deleted file mode 100644 index 6f42801061b..00000000000 --- 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 00000000000..fa91d0a73ac --- /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 ef5456a1bd1..44d7dbccba1 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()); -- cgit v1.2.3 From 52e7bf96306a048c43d77d5c3db42f89187f45ce Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 28 May 2014 22:42:33 +0200 Subject: 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(-) (limited to 'core/register_command.php') diff --git a/core/command/resetpassword.php b/core/command/resetpassword.php index b5184042e35..ab877655e27 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 44d7dbccba1..e9b62508883 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()); -- cgit v1.2.3 From f81ee94cad8a997c3a2fef0b6aac4f8d509571f6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 28 May 2014 22:53:44 +0200 Subject: Move resetpassword into user: command space. --- core/command/resetpassword.php | 79 ------------------------------------- core/command/user/resetpassword.php | 79 +++++++++++++++++++++++++++++++++++++ core/register_command.php | 2 +- 3 files changed, 80 insertions(+), 80 deletions(-) delete mode 100644 core/command/resetpassword.php create mode 100644 core/command/user/resetpassword.php (limited to 'core/register_command.php') diff --git a/core/command/resetpassword.php b/core/command/resetpassword.php deleted file mode 100644 index ddff7a980d0..00000000000 --- a/core/command/resetpassword.php +++ /dev/null @@ -1,79 +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 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') - ->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'); - - /** @var $user \OC\User\User */ - $user = $this->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'); - $password = $dialog->askHiddenResponse( - $output, - 'Enter a new password: ', - false - ); - $confirm = $dialog->askHiddenResponse( - $output, - 'Confirm the new password: ', - false - ); - - if ($password === $confirm) { - $success = $user->setPassword($password); - if ($success) { - $output->writeln("Successfully reset password for " . $username . ""); - } else { - $output->writeln("Error while resetting password!"); - return 1; - } - } else { - $output->writeln("Passwords did not match!"); - return 1; - } - } else { - $output->writeln("Interactive input is needed for entering a new password!"); - return 1; - } - } -} diff --git a/core/command/user/resetpassword.php b/core/command/user/resetpassword.php new file mode 100644 index 00000000000..d7893c291e4 --- /dev/null +++ b/core/command/user/resetpassword.php @@ -0,0 +1,79 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Core\Command\User; + +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 { + + /** @var \OC\User\Manager */ + protected $userManager; + + public function __construct(\OC\User\Manager $userManager) { + $this->userManager = $userManager; + parent::__construct(); + } + + protected function configure() { + $this + ->setName('user: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'); + + /** @var $user \OC\User\User */ + $user = $this->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'); + $password = $dialog->askHiddenResponse( + $output, + 'Enter a new password: ', + false + ); + $confirm = $dialog->askHiddenResponse( + $output, + 'Confirm the new password: ', + false + ); + + if ($password === $confirm) { + $success = $user->setPassword($password); + if ($success) { + $output->writeln("Successfully reset password for " . $username . ""); + } else { + $output->writeln("Error while resetting password!"); + return 1; + } + } else { + $output->writeln("Passwords did not match!"); + return 1; + } + } else { + $output->writeln("Interactive input is needed for entering a new password!"); + return 1; + } + } +} diff --git a/core/register_command.php b/core/register_command.php index e9b62508883..8efd2673afe 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())); -- cgit v1.2.3