$users collection of system user ids * * @return DataResponse * * 200: user/provider states */ #[PublicPage] #[ApiRoute(verb: 'POST', url: '/state', root: '/twofactor')] public function state(array $users = []): DataResponse { $states = []; foreach ($users as $userId) { $userObject = $this->userManager->get($userId); if ($userObject !== null) { $states[$userId] = $this->tfRegistry->getProviderStates($userObject); } } return new DataResponse($states); } /** * Enable two factor authentication providers for specific user * * @param string $user system user identifier * @param list $providers collection of TFA provider ids * * @return DataResponse * * 200: provider states * 404: user not found */ #[PublicPage] #[ApiRoute(verb: 'POST', url: '/enable', root: '/twofactor')] public function enable(string $user, array $providers = []): DataResponse { $userObject = $this->userManager->get($user); if ($userObject !== null) { if (is_array($providers)) { foreach ($providers as $providerId) { $this->tfManager->tryEnableProviderFor($providerId, $userObject); } } $state = $this->tfRegistry->getProviderStates($userObject); return new DataResponse($state); } return new DataResponse([], Http::STATUS_NOT_FOUND); } /** * Disable two factor authentication providers for specific user * * @param string $user system user identifier * @param list $providers collection of TFA provider ids * * @return DataResponse * * 200: provider states * 404: user not found */ #[PublicPage] #[ApiRoute(verb: 'POST', url: '/disable', root: '/twofactor')] public function disable(string $user, array $providers = []): DataResponse { $userObject = $this->userManager->get($user); if ($userObject !== null) { if (is_array($providers)) { foreach ($providers as $providerId) { $this->tfManager->tryDisableProviderFor($providerId, $userObject); } } $state = $this->tfRegistry->getProviderStates($userObject); return new DataResponse($state); } return new DataResponse([], Http::STATUS_NOT_FOUND); } }