|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * @author Christoph Wurst <[email protected]> |
| 7 | + * @author Simon Spannagel <[email protected]> |
| 8 | + * |
| 9 | + * Nextcloud - Two-factor Gateway |
| 10 | + * |
| 11 | + * This code is free software: you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU Affero General Public License, version 3, |
| 13 | + * as published by the Free Software Foundation. |
| 14 | + * |
| 15 | + * This program is distributed in the hope that it will be useful, |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | + * GNU Affero General Public License for more details. |
| 19 | + * |
| 20 | + * You should have received a copy of the GNU Affero General Public License, version 3, |
| 21 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 22 | + * |
| 23 | + */ |
| 24 | + |
| 25 | +namespace OCA\TwoFactorGateway\Command; |
| 26 | + |
| 27 | +use OCA\TwoFactorGateway\Service\Gateway\Signal\Gateway as SignalGateway; |
| 28 | +use OCA\TwoFactorGateway\Service\Gateway\SMS\Gateway as SMSGateway; |
| 29 | +use OCA\TwoFactorGateway\Service\Gateway\Telegram\Gateway as TelegramGateway; |
| 30 | +use Symfony\Component\Console\Command\Command; |
| 31 | +use Symfony\Component\Console\Input\InputArgument; |
| 32 | +use Symfony\Component\Console\Input\InputInterface; |
| 33 | +use Symfony\Component\Console\Output\OutputInterface; |
| 34 | + |
| 35 | +class Remove extends Command { |
| 36 | + |
| 37 | + /** @var SignalGateway */ |
| 38 | + private $signalGateway; |
| 39 | + |
| 40 | + /** @var SMSGateway */ |
| 41 | + private $smsGateway; |
| 42 | + |
| 43 | + /** @var TelegramGateway */ |
| 44 | + private $telegramGateway; |
| 45 | + |
| 46 | + public function __construct(SignalGateway $signalGateway, |
| 47 | + SMSGateway $smsGateway, |
| 48 | + TelegramGateway $telegramGateway) { |
| 49 | + parent::__construct('twofactorauth:gateway:remove'); |
| 50 | + $this->signalGateway = $signalGateway; |
| 51 | + $this->smsGateway = $smsGateway; |
| 52 | + $this->telegramGateway = $telegramGateway; |
| 53 | + |
| 54 | + $this->addArgument( |
| 55 | + 'gateway', |
| 56 | + InputArgument::REQUIRED, |
| 57 | + 'The name of the gateway, e.g. sms, signal, telegram, etc.' |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + protected function execute(InputInterface $input, OutputInterface $output) { |
| 62 | + $gatewayName = $input->getArgument('gateway'); |
| 63 | + |
| 64 | + /** @var IGateway $gateway */ |
| 65 | + $gateway = null; |
| 66 | + switch ($gatewayName) { |
| 67 | + case 'signal': |
| 68 | + $gateway = $this->signalGateway; |
| 69 | + break; |
| 70 | + case 'sms': |
| 71 | + $gateway = $this->smsGateway; |
| 72 | + break; |
| 73 | + case 'telegram': |
| 74 | + $gateway = $this->telegramGateway; |
| 75 | + break; |
| 76 | + default: |
| 77 | + $output->writeln("<error>Invalid gateway $gatewayName</error>"); |
| 78 | + return 1; |
| 79 | + } |
| 80 | + |
| 81 | + $gateway->getConfig()->remove(); |
| 82 | + $output->writeln("Removed configuration for gateway $gatewayName"); |
| 83 | + return 0; |
| 84 | + } |
| 85 | +} |
0 commit comments