diff --git a/src/Results/BaseResults.php b/src/Results/BaseResults.php index 37bf787..2f3e8c1 100644 --- a/src/Results/BaseResults.php +++ b/src/Results/BaseResults.php @@ -26,17 +26,23 @@ class BaseResults */ private ?Exception $exception; + /** + * @var string|null Contains the ID of the token that was validated. + */ + private ?string $tokenId; + /** * BaseResults constructor. * * @param bool $validationSucceed Indicates if the validation process succeeded or not. * @param string|null $cause Contains a message explaining why the validation process failed. */ - public function __construct(bool $validationSucceed, ?string $cause = null, ?Exception $exception = null) + public function __construct(bool $validationSucceed, ?string $cause = null, ?Exception $exception = null, ?string $tokenId = null) { $this->validationSucceed = $validationSucceed; $this->cause = $cause; $this->exception = $exception; + $this->tokenId = $tokenId; } /** @@ -69,6 +75,16 @@ public function getException(): ?Exception return $this->exception; } + /** + * Getter method for the ID of the token that was validated. + * + * @return string|null Contains the ID of the token that was validated. + */ + public function getTokenId(): ?string + { + return $this->tokenId; + } + /** * Creates a new BaseResultsBuilder object to build a new BaseResults instance. * diff --git a/src/Results/BaseResultsBuilder.php b/src/Results/BaseResultsBuilder.php index 607389c..5a356c8 100644 --- a/src/Results/BaseResultsBuilder.php +++ b/src/Results/BaseResultsBuilder.php @@ -14,6 +14,7 @@ class BaseResultsBuilder private bool $validationSucceed; private ?string $cause; private ?Exception $exception; + private ?string $tokenId; /** * BaseResultsBuilder constructor. @@ -23,6 +24,7 @@ public function __construct() $this->validationSucceed = false; $this->cause = null; $this->exception = null; + $this->tokenId = null; } /** @@ -61,6 +63,18 @@ public function setException(?Exception $exception): self return $this; } + /** + * Sets the ID of the token that was validated. + * + * @param string|null $tokenId Contains the ID of the token that was validated. + * @return $this This instance of the BaseResultsBuilder object. + */ + public function setTokenId(?string $tokenId): self + { + $this->tokenId = $tokenId; + return $this; + } + /** * Builds the BaseResults object with the provided values. * @@ -68,7 +82,7 @@ public function setException(?Exception $exception): self */ public function build(): BaseResults { - return new BaseResults($this->validationSucceed, $this->cause, $this->exception); + return new BaseResults($this->validationSucceed, $this->cause, $this->exception, $this->tokenId); } /** diff --git a/src/TokensValidation.php b/src/TokensValidation.php index b706e85..a25584a 100644 --- a/src/TokensValidation.php +++ b/src/TokensValidation.php @@ -543,9 +543,9 @@ private static function checkAuthToken_(string $fingerPrint, ?string $authToken, $authTokenModel = $authTokenModel[0]; $authTokenResultBuilder->setUserId($authTokenModel->userId); if (!self::isExpired(DateTime::createFromFormat('Y-m-d H:i:s', $authTokenModel->expire_at))) { - if ($authTokenModel->fingerprint == '' || $authTokenModel->fingerprint == $fingerPrint) { $authTokenResultBuilder->setValidationSucceed(true); + $authTokenResultBuilder->setTokenId(strval($authTokenModel->id??"")); if ($regenerate) { $newToken = self::regenerateAuthToken($authTokenModel->userId, $token, $authTokenModel->type); $authTokenResultBuilder->setNewToken($newToken); @@ -639,6 +639,7 @@ public static function checkConfirmationCode(string $code, string $encryptedUser if ($confirmationTokenModel->whatFor == $whatFor || $whatFor == "default") { $confirmationTokenResultsBuilder->setValidationSucceed(true); $confirmationTokenResultsBuilder->withWhatFor($whatFor); + $confirmationTokenResultsBuilder->setTokenId(strval($confirmationTokenModel->id??"")); if ($deleteAfterCheck) { ConfirmationTokenModel::find($confirmationTokenModel->id)->delete(); } @@ -790,6 +791,7 @@ public static function checkInvitationToken(string $token, string $whatFor = "de $invitationResultsBuilder->withUserId($invitationModel->userId); if (!self::isExpired(DateTime::createFromFormat('Y-m-d H:i:s', $invitationModel->expire_at))) { if ($invitationModel->whatFor == $whatFor || $whatFor == "default") { + $invitationResultsBuilder->setTokenId(strval($invitationModel->id??"")); $invitationResultsBuilder->setValidationSucceed(true); $invitationResultsBuilder->withData($invitationModel->data); $invitationResultsBuilder->withTargetEmail($invitationModel->target_email);