1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author Christian Schrötter <[email protected]> |
7
|
|
|
* @author Christoph Wurst <[email protected]> |
8
|
|
|
* @author André Fondse <[email protected]> |
9
|
|
|
* |
10
|
|
|
* Nextcloud - Two-factor Gateway for Telegram |
11
|
|
|
* |
12
|
|
|
* This code is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
14
|
|
|
* as published by the Free Software Foundation. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider; |
27
|
|
|
|
28
|
|
|
use OCA\TwoFactorGateway\AppInfo\Application; |
29
|
|
|
use OCA\TwoFactorGateway\Exception\ConfigurationException; |
30
|
|
|
use OCP\IConfig; |
31
|
|
|
|
32
|
|
|
class ClickatellCentralConfig implements IProviderConfig { |
33
|
|
|
|
34
|
|
|
/** @var IConfig */ |
35
|
|
|
private $config; |
36
|
|
|
|
37
|
|
|
public function __construct(IConfig $config) { |
38
|
|
|
$this->config = $config; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
private function getOrFail(string $key): string { |
42
|
|
|
$val = $this->config->getAppValue(Application::APP_NAME, $key, null); |
43
|
|
|
if (is_null($val)) { |
|
|
|
|
44
|
|
|
throw new ConfigurationException(); |
45
|
|
|
} |
46
|
|
|
return $val; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getApi(): string { |
50
|
|
|
return $this->getOrFail('clickatell_central_api'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function setApi(string $api) { |
54
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'clickatell_central_api', $api); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getUser(): string { |
58
|
|
|
return $this->getOrFail('clickatell_central_user'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function setUser(string $user) { |
62
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'clickatell_central_user', $user); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getPassword(): string { |
66
|
|
|
return $this->getOrFail('clickatell_central_password'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function setPassword(string $password) { |
70
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'clickatell_central_password', $password); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function isComplete(): bool { |
74
|
|
|
$set = $this->config->getAppKeys(Application::APP_NAME); |
75
|
|
|
$expected = [ |
76
|
|
|
'clickatell_central_api', |
77
|
|
|
'clickatell_central_user', |
78
|
|
|
'clickatell_central_password', |
79
|
|
|
]; |
80
|
|
|
return count(array_intersect($set, $expected)) === count($expected); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|