1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author Christoph Wurst <[email protected]> |
7
|
|
|
* @author André Fondse <[email protected]> |
8
|
|
|
* |
9
|
|
|
* Nextcloud - Two-factor Gateway for Telegram |
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\Service\Gateway\SMS\Provider; |
26
|
|
|
|
27
|
|
|
use OCA\TwoFactorGateway\AppInfo\Application; |
28
|
|
|
use OCA\TwoFactorGateway\Exception\ConfigurationException; |
29
|
|
|
use OCP\IConfig; |
30
|
|
|
|
31
|
|
|
class WebSmsConfig implements IProviderConfig { |
32
|
|
|
|
33
|
|
|
const expected = [ |
34
|
|
|
'websms_de_user', |
35
|
|
|
'websms_de_password', |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
/** @var IConfig */ |
39
|
|
|
private $config; |
40
|
|
|
|
41
|
|
|
public function __construct(IConfig $config) { |
42
|
|
|
$this->config = $config; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
private function getOrFail(string $key): string { |
46
|
|
|
$val = $this->config->getAppValue(Application::APP_NAME, $key, null); |
47
|
|
|
if (is_null($val)) { |
|
|
|
|
48
|
|
|
throw new ConfigurationException(); |
49
|
|
|
} |
50
|
|
|
return $val; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getUser(): string { |
54
|
|
|
return $this->getOrFail('websms_de_user'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function setUser(string $user) { |
58
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'websms_de_user', $user); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getPassword(): string { |
62
|
|
|
return $this->getOrFail('websms_de_password'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function setPassword(string $password) { |
66
|
|
|
$this->config->setAppValue(Application::APP_NAME, 'websms_de_password', $password); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function isComplete(): bool { |
70
|
|
|
$set = $this->config->getAppKeys(Application::APP_NAME); |
71
|
|
|
return count(array_intersect($set, self::expected)) === count(self::expected); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function remove() { |
75
|
|
|
foreach(self::expected as $key) { |
76
|
|
|
$this->config->deleteAppValue(Application::APP_NAME, $key); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|