1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author Christoph Wurst <[email protected]> |
7
|
|
|
* |
8
|
|
|
* Nextcloud - Two-factor Gateway |
9
|
|
|
* |
10
|
|
|
* This code is free software: you can redistribute it and/or modify |
11
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
12
|
|
|
* as published by the Free Software Foundation. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\TwoFactorGateway\Service\Gateway\SMS; |
25
|
|
|
|
26
|
|
|
use OCA\TwoFactorGateway\AppInfo\Application; |
27
|
|
|
use OCA\TwoFactorGateway\Exception\ConfigurationException; |
28
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\IGatewayConfig; |
29
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\IProvider; |
30
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ProviderFactory; |
31
|
|
|
use OCP\IConfig; |
32
|
|
|
|
33
|
|
|
class GatewayConfig implements IGatewayConfig { |
34
|
|
|
|
35
|
|
|
/** @var IConfig */ |
36
|
|
|
private $config; |
37
|
|
|
|
38
|
|
|
/** @var ProviderFactory */ |
39
|
|
|
private $providerFactory; |
40
|
|
|
|
41
|
|
|
public function __construct(IConfig $config, |
42
|
|
|
ProviderFactory $providerFactory) { |
43
|
|
|
$this->config = $config; |
44
|
|
|
$this->providerFactory = $providerFactory; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getProvider(): IProvider { |
48
|
|
|
$providerName = $this->config->getAppValue(Application::APP_NAME, 'sms_provider_name'); |
49
|
|
|
if ($providerName === '') { |
50
|
|
|
throw new ConfigurationException(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $this->providerFactory->getProvider($providerName); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function setProvider(string $provider) { |
57
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'sms_provider_name', $provider); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function isComplete(): bool { |
61
|
|
|
try { |
62
|
|
|
$provider = $this->getProvider(); |
63
|
|
|
return $provider->getConfig()->isComplete(); |
64
|
|
|
} catch (ConfigurationException $ex) { |
65
|
|
|
return false; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function remove() { |
70
|
|
|
$this->getProvider()->getConfig()->remove(); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|