mirror of
https://github.com/nextcloud/server.git
synced 2025-03-04 03:57:28 +00:00
52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
namespace OCA\TwoFactorBackupCodes\Controller;
|
|
|
|
use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage;
|
|
use OCP\AppFramework\Controller;
|
|
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
|
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
use OCP\IRequest;
|
|
use OCP\IUserSession;
|
|
|
|
class SettingsController extends Controller {
|
|
|
|
/** @var BackupCodeStorage */
|
|
private $storage;
|
|
|
|
/** @var IUserSession */
|
|
private $userSession;
|
|
|
|
/**
|
|
* @param string $appName
|
|
* @param IRequest $request
|
|
* @param BackupCodeStorage $storage
|
|
* @param IUserSession $userSession
|
|
*/
|
|
public function __construct($appName, IRequest $request, BackupCodeStorage $storage, IUserSession $userSession) {
|
|
parent::__construct($appName, $request);
|
|
$this->userSession = $userSession;
|
|
$this->storage = $storage;
|
|
}
|
|
|
|
/**
|
|
* @return JSONResponse
|
|
*/
|
|
#[NoAdminRequired]
|
|
#[PasswordConfirmationRequired]
|
|
public function createCodes(): JSONResponse {
|
|
$user = $this->userSession->getUser();
|
|
$codes = $this->storage->createCodes($user);
|
|
return new JSONResponse([
|
|
'codes' => $codes,
|
|
'state' => $this->storage->getBackupCodesState($user),
|
|
]);
|
|
}
|
|
}
|