mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
authentication: bypass second step
This commit is contained in:
@@ -232,6 +232,7 @@ class Authentication
|
||||
$this->applicationUser->setUser($loggedUser);
|
||||
|
||||
if (
|
||||
!$result->bypassSecondStep() &&
|
||||
!$result->isSecondStepRequired() &&
|
||||
!$authToken &&
|
||||
$this->configDataProvider->isTwoFactorEnabled()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user