mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 16:26:59 -04:00
Only check the twofactor state once per request
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
3a1ef2b012
commit
660e550260
1 changed files with 9 additions and 1 deletions
|
|
@ -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()];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue