0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-02-06 01:20:16 +00:00
nextcloud_server/apps/twofactor_backupcodes/lib/Controller/SettingsController.php
provokateurin 381077028a
refactor(apps): Use constructor property promotion when possible
Signed-off-by: provokateurin <kate@provokateurin.de>
2024-10-21 12:37:59 +02:00

49 lines
1.2 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 {
/**
* @param string $appName
* @param IRequest $request
* @param BackupCodeStorage $storage
* @param IUserSession $userSession
*/
public function __construct(
$appName,
IRequest $request,
private BackupCodeStorage $storage,
private IUserSession $userSession,
) {
parent::__construct($appName, $request);
}
/**
* @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),
]);
}
}