authentication: bypass second step

This commit is contained in:
Yuri Kuznetsov
2024-07-31 14:12:09 +03:00
parent 8018478b13
commit a109e1353d
3 changed files with 25 additions and 2 deletions

View File

@@ -232,6 +232,7 @@ class Authentication
$this->applicationUser->setUser($loggedUser);
if (
!$result->bypassSecondStep() &&
!$result->isSecondStepRequired() &&
!$authToken &&
$this->configDataProvider->isTwoFactorEnabled()

View File

@@ -152,7 +152,7 @@ class Login implements LoginInterface
return Result::fail(FailReason::USER_NOT_FOUND);
}
return Result::success($user);
return Result::success($user)->withBypassSecondStep();
}
private function loginFallback(Data $data, Request $request): Result

View File

@@ -51,6 +51,7 @@ class Result
private ?string $token = null;
private ?string $view = null;
private ?string $failReason = null;
private bool $bypassSecondStep = false;
private ?Data $data;
private function __construct(string $status, ?User $user = null, ?Data $data = null)
@@ -105,13 +106,23 @@ class Result
}
/**
* Second step is required. E.g. for 2FA.
* The second step is required.
*/
public function isSecondStepRequired(): bool
{
return $this->status === self::STATUS_SECOND_STEP_REQUIRED;
}
/**
* To bypass the second step.
*
* @since 8.4.0
*/
public function bypassSecondStep(): bool
{
return $this->bypassSecondStep;
}
/**
* Login is failed.
*/
@@ -183,4 +194,15 @@ class Result
{
return $this->failReason;
}
/**
* Clone with bypass the second step.
*/
public function withBypassSecondStep(bool $bypassSecondStep = true): self
{
$obj = clone $this;
$obj->bypassSecondStep = $bypassSecondStep;
return $obj;
}
}