aboutsummaryrefslogtreecommitdiffstats
path: root/apps/twofactor_backupcodes/lib/Controller/SettingsController.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/twofactor_backupcodes/lib/Controller/SettingsController.php')
-rw-r--r--apps/twofactor_backupcodes/lib/Controller/SettingsController.php49
1 files changed, 49 insertions, 0 deletions
diff --git a/apps/twofactor_backupcodes/lib/Controller/SettingsController.php b/apps/twofactor_backupcodes/lib/Controller/SettingsController.php
new file mode 100644
index 00000000000..effc058e05c
--- /dev/null
+++ b/apps/twofactor_backupcodes/lib/Controller/SettingsController.php
@@ -0,0 +1,49 @@
+<?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),
+ ]);
+ }
+}