1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Christoph Wurst <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @license GNU AGPL version 3 or any later version |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
11
|
|
|
* License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace OCA\TwoFactorBackupCodes\Controller; |
24
|
|
|
|
25
|
|
|
use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage; |
26
|
|
|
use OCP\AppFramework\Controller; |
27
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
28
|
|
|
use OCP\IRequest; |
29
|
|
|
use OCP\IUserSession; |
30
|
|
|
|
31
|
|
|
class SettingsController extends Controller { |
32
|
|
|
|
33
|
|
|
/** @var BackupCodeStorage */ |
34
|
|
|
private $storage; |
35
|
|
|
|
36
|
|
|
/** @var IUserSession */ |
37
|
|
|
private $userSession; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $appName |
41
|
|
|
* @param IRequest $request |
42
|
|
|
* @param BackupCodeStorage $storage |
43
|
|
|
* @param IUserSession $userSession |
44
|
|
|
*/ |
45
|
|
|
public function __construct($appName, IRequest $request, BackupCodeStorage $storage, IUserSession $userSession) { |
46
|
|
|
parent::__construct($appName, $request); |
47
|
|
|
$this->userSession = $userSession; |
48
|
|
|
$this->storage = $storage; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @NoAdminRequired |
53
|
|
|
* @PasswordConfirmationRequired |
54
|
|
|
* |
55
|
|
|
* @return JSONResponse |
56
|
|
|
*/ |
57
|
|
|
public function createCodes() { |
58
|
|
|
$user = $this->userSession->getUser(); |
59
|
|
|
$codes = $this->storage->createCodes($user); |
60
|
|
|
return new JSONResponse([ |
61
|
|
|
'codes' => $codes, |
62
|
|
|
'state' => $this->storage->getBackupCodesState($user), |
63
|
|
|
]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|