1<?php
2/**
3 * @author Christoph Wurst <christoph@owncloud.com>
4 *
5 * @copyright Copyright (c) 2018, ownCloud GmbH
6 * @license AGPL-3.0
7 *
8 * This code is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License, version 3,
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License, version 3,
18 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19 *
20 */
21
22namespace OC\Core\Command\TwoFactorAuth;
23
24use OC\Authentication\TwoFactorAuth\Manager;
25use OC\User\Manager as UserManager;
26use OC\Core\Command\Base;
27use Symfony\Component\Console\Input\InputArgument;
28use Symfony\Component\Console\Input\InputInterface;
29use Symfony\Component\Console\Output\OutputInterface;
30
31class Disable extends Base {
32
33	/** @var Manager */
34	private $manager;
35
36	/** @var UserManager */
37	private $userManager;
38
39	public function __construct(Manager $manager, UserManager $userManager) {
40		parent::__construct('twofactorauth:disable');
41		$this->manager = $manager;
42		$this->userManager = $userManager;
43	}
44
45	protected function configure() {
46		parent::configure();
47
48		$this->setName('twofactorauth:disable');
49		$this->setDescription('Disable two-factor authentication for a user.');
50		$this->addArgument('uid', InputArgument::REQUIRED);
51	}
52
53	protected function execute(InputInterface $input, OutputInterface $output) {
54		$uid = $input->getArgument('uid');
55		$user = $this->userManager->get($uid);
56		if ($user === null) {
57			$output->writeln("<error>Invalid UID</error>");
58			return;
59		}
60		$this->manager->disableTwoFactorAuthentication($user);
61		$output->writeln("Two-factor authentication disabled for user $uid");
62	}
63}
64