TwoFactorSettingsController.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\Controller;
  8. use OC\Authentication\TwoFactorAuth\EnforcementState;
  9. use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
  10. use OCP\AppFramework\Controller;
  11. use OCP\AppFramework\Http\JSONResponse;
  12. use OCP\IRequest;
  13. class TwoFactorSettingsController extends Controller {
  14. /** @var MandatoryTwoFactor */
  15. private $mandatoryTwoFactor;
  16. public function __construct(string $appName,
  17. IRequest $request,
  18. MandatoryTwoFactor $mandatoryTwoFactor) {
  19. parent::__construct($appName, $request);
  20. $this->mandatoryTwoFactor = $mandatoryTwoFactor;
  21. }
  22. public function index(): JSONResponse {
  23. return new JSONResponse($this->mandatoryTwoFactor->getState());
  24. }
  25. public function update(bool $enforced, array $enforcedGroups = [], array $excludedGroups = []): JSONResponse {
  26. $this->mandatoryTwoFactor->setState(
  27. new EnforcementState($enforced, $enforcedGroups, $excludedGroups)
  28. );
  29. return new JSONResponse($this->mandatoryTwoFactor->getState());
  30. }
  31. }