Passed
Push — master ( 3f4776...edd957 )
by Roeland
12:26 queued 12s
created

Registry::deleteUserData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright 2018 Christoph Wurst <[email protected]>
7
 *
8
 * @author Christoph Wurst <[email protected]>
9
 * @author Roeland Jago Douma <[email protected]>
10
 *
11
 * @license GNU AGPL version 3 or any later version
12
 *
13
 * This program is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Affero General Public License as
15
 * published by the Free Software Foundation, either version 3 of the
16
 * License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU Affero General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License
24
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25
 *
26
 */
27
28
namespace OC\Authentication\TwoFactorAuth;
29
30
use OC\Authentication\TwoFactorAuth\Db\ProviderUserAssignmentDao;
31
use OCP\Authentication\TwoFactorAuth\IProvider;
32
use OCP\Authentication\TwoFactorAuth\IRegistry;
33
use OCP\Authentication\TwoFactorAuth\RegistryEvent;
34
use OCP\EventDispatcher\IEventDispatcher;
35
use OCP\IUser;
36
37
class Registry implements IRegistry {
38
39
	/** @var ProviderUserAssignmentDao */
40
	private $assignmentDao;
41
42
	/** @var IEventDispatcher */
43
	private $dispatcher;
44
45
	public function __construct(ProviderUserAssignmentDao $assignmentDao,
46
								IEventDispatcher $dispatcher) {
47
		$this->assignmentDao = $assignmentDao;
48
		$this->dispatcher = $dispatcher;
49
	}
50
51
	public function getProviderStates(IUser $user): array {
52
		return $this->assignmentDao->getState($user->getUID());
53
	}
54
55
	public function enableProviderFor(IProvider $provider, IUser $user) {
56
		$this->assignmentDao->persist($provider->getId(), $user->getUID(), 1);
57
58
		$event = new RegistryEvent($provider, $user);
59
		$this->dispatcher->dispatch(self::EVENT_PROVIDER_ENABLED, $event);
60
	}
61
62
	public function disableProviderFor(IProvider $provider, IUser $user) {
63
		$this->assignmentDao->persist($provider->getId(), $user->getUID(), 0);
64
65
		$event = new RegistryEvent($provider, $user);
66
		$this->dispatcher->dispatch(self::EVENT_PROVIDER_DISABLED, $event);
67
	}
68
69
	/**
70
	 * @todo evaluate if we should emit RegistryEvents for each of the deleted rows -> needs documentation
71
	 */
72
	public function deleteUserData(IUser $user): void {
73
		$this->assignmentDao->deleteByUser($user->getUID());
74
	}
75
76
	public function cleanUp(string $providerId) {
77
		$this->assignmentDao->deleteAll($providerId);
78
	}
79
}
80