Disable.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Core\Command\TwoFactorAuth;
  8. use OC\Authentication\TwoFactorAuth\ProviderManager;
  9. use OCP\IUserManager;
  10. use Symfony\Component\Console\Input\InputArgument;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. class Disable extends Base {
  14. public function __construct(
  15. private ProviderManager $manager,
  16. IUserManager $userManager,
  17. ) {
  18. parent::__construct(
  19. 'twofactorauth:disable',
  20. $userManager,
  21. );
  22. }
  23. protected function configure() {
  24. parent::configure();
  25. $this->setName('twofactorauth:disable');
  26. $this->setDescription('Disable two-factor authentication for a user');
  27. $this->addArgument('uid', InputArgument::REQUIRED);
  28. $this->addArgument('provider_id', InputArgument::REQUIRED);
  29. }
  30. protected function execute(InputInterface $input, OutputInterface $output): int {
  31. $uid = $input->getArgument('uid');
  32. $providerId = $input->getArgument('provider_id');
  33. $user = $this->userManager->get($uid);
  34. if (is_null($user)) {
  35. $output->writeln("<error>Invalid UID</error>");
  36. return 1;
  37. }
  38. if ($this->manager->tryDisableProviderFor($providerId, $user)) {
  39. $output->writeln("Two-factor provider <options=bold>$providerId</> disabled for user <options=bold>$uid</>.");
  40. return 0;
  41. } else {
  42. $output->writeln("<error>The provider does not support this operation.</error>");
  43. return 2;
  44. }
  45. }
  46. }