Merge pull request #30012 from nextcloud/bugfix/noid/only-check-2fa-state-once

This commit is contained in:
John Molakvoæ 2021-12-01 18:38:24 +01:00 committed by GitHub
commit c21173ff27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -87,6 +87,9 @@ class Manager {
/** @var EventDispatcherInterface */
private $legacyDispatcher;
/** @psalm-var array<string, bool> */
private $userIsTwoFactorAuthenticated = [];
public function __construct(ProviderLoader $providerLoader,
IRegistry $providerRegistry,
MandatoryTwoFactor $mandatoryTwoFactor,
@ -118,6 +121,10 @@ class Manager {
* @return boolean
*/
public function isTwoFactorAuthenticated(IUser $user): bool {
if (isset($this->userIsTwoFactorAuthenticated[$user->getUID()])) {
return $this->userIsTwoFactorAuthenticated[$user->getUID()];
}
if ($this->mandatoryTwoFactor->isEnforcedFor($user)) {
return true;
}
@ -129,7 +136,8 @@ class Manager {
$providerIds = array_keys($enabled);
$providerIdsWithoutBackupCodes = array_diff($providerIds, [self::BACKUP_CODES_PROVIDER_ID]);
return !empty($providerIdsWithoutBackupCodes);
$this->userIsTwoFactorAuthenticated[$user->getUID()] = !empty($providerIdsWithoutBackupCodes);
return $this->userIsTwoFactorAuthenticated[$user->getUID()];
}
/**