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
|
|
|
|
26
|
|
|
namespace OCA\TwoFactorGateway\Service\Gateway\Telegram; |
27
|
|
|
|
28
|
|
|
use OCA\TwoFactorGateway\AppInfo\Application; |
29
|
|
|
use OCA\TwoFactorGateway\Exception\ConfigurationException; |
30
|
|
|
use OCA\TwoFactorGateway\Service\Gateway\IGatewayConfig; |
31
|
|
|
use OCP\IConfig; |
32
|
|
|
|
33
|
|
|
class GatewayConfig implements IGatewayConfig { |
34
|
|
|
private const expected = [ |
35
|
|
|
'telegram_bot_token', |
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_ID, $key); |
47
|
|
|
if ($val === '') { |
48
|
|
|
throw new ConfigurationException(); |
49
|
|
|
} |
50
|
|
|
return $val; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getBotToken(): string { |
54
|
|
|
return $this->getOrFail('telegram_bot_token'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function setBotToken(string $token) { |
58
|
|
|
$this->config->setAppValue(Application::APP_ID, 'telegram_bot_token', $token); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function isComplete(): bool { |
62
|
|
|
$set = $this->config->getAppKeys(Application::APP_ID); |
63
|
|
|
return count(array_intersect($set, self::expected)) === count(self::expected); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function remove() { |
67
|
|
|
foreach (self::expected as $key) { |
68
|
|
|
$this->config->deleteAppValue(Application::APP_ID, $key); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|