Skip to content

Commit cf6d401

Browse files
add token id getter
1 parent 62bdf96 commit cf6d401

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

src/Results/BaseResults.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,23 @@ class BaseResults
2626
*/
2727
private ?Exception $exception;
2828

29+
/**
30+
* @var string|null Contains the ID of the token that was validated.
31+
*/
32+
private ?string $tokenId;
33+
2934
/**
3035
* BaseResults constructor.
3136
*
3237
* @param bool $validationSucceed Indicates if the validation process succeeded or not.
3338
* @param string|null $cause Contains a message explaining why the validation process failed.
3439
*/
35-
public function __construct(bool $validationSucceed, ?string $cause = null, ?Exception $exception = null)
40+
public function __construct(bool $validationSucceed, ?string $cause = null, ?Exception $exception = null, ?string $tokenId = null)
3641
{
3742
$this->validationSucceed = $validationSucceed;
3843
$this->cause = $cause;
3944
$this->exception = $exception;
45+
$this->tokenId = $tokenId;
4046
}
4147

4248
/**
@@ -69,6 +75,16 @@ public function getException(): ?Exception
6975
return $this->exception;
7076
}
7177

78+
/**
79+
* Getter method for the ID of the token that was validated.
80+
*
81+
* @return string|null Contains the ID of the token that was validated.
82+
*/
83+
public function getTokenId(): ?string
84+
{
85+
return $this->tokenId;
86+
}
87+
7288
/**
7389
* Creates a new BaseResultsBuilder object to build a new BaseResults instance.
7490
*

src/Results/BaseResultsBuilder.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class BaseResultsBuilder
1414
private bool $validationSucceed;
1515
private ?string $cause;
1616
private ?Exception $exception;
17+
private ?string $tokenId;
1718

1819
/**
1920
* BaseResultsBuilder constructor.
@@ -23,6 +24,7 @@ public function __construct()
2324
$this->validationSucceed = false;
2425
$this->cause = null;
2526
$this->exception = null;
27+
$this->tokenId = null;
2628
}
2729

2830
/**
@@ -61,14 +63,26 @@ public function setException(?Exception $exception): self
6163
return $this;
6264
}
6365

66+
/**
67+
* Sets the ID of the token that was validated.
68+
*
69+
* @param string|null $tokenId Contains the ID of the token that was validated.
70+
* @return $this This instance of the BaseResultsBuilder object.
71+
*/
72+
public function setTokenId(?string $tokenId): self
73+
{
74+
$this->tokenId = $tokenId;
75+
return $this;
76+
}
77+
6478
/**
6579
* Builds the BaseResults object with the provided values.
6680
*
6781
* @return BaseResults The resulting BaseResults object.
6882
*/
6983
public function build(): BaseResults
7084
{
71-
return new BaseResults($this->validationSucceed, $this->cause, $this->exception);
85+
return new BaseResults($this->validationSucceed, $this->cause, $this->exception, $this->tokenId);
7286
}
7387

7488
/**

src/TokensValidation.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,9 @@ private static function checkAuthToken_(string $fingerPrint, ?string $authToken,
543543
$authTokenModel = $authTokenModel[0];
544544
$authTokenResultBuilder->setUserId($authTokenModel->userId);
545545
if (!self::isExpired(DateTime::createFromFormat('Y-m-d H:i:s', $authTokenModel->expire_at))) {
546-
547546
if ($authTokenModel->fingerprint == '' || $authTokenModel->fingerprint == $fingerPrint) {
548547
$authTokenResultBuilder->setValidationSucceed(true);
548+
$authTokenResultBuilder->setTokenId(strval($authTokenModel->id??""));
549549
if ($regenerate) {
550550
$newToken = self::regenerateAuthToken($authTokenModel->userId, $token, $authTokenModel->type);
551551
$authTokenResultBuilder->setNewToken($newToken);
@@ -639,6 +639,7 @@ public static function checkConfirmationCode(string $code, string $encryptedUser
639639
if ($confirmationTokenModel->whatFor == $whatFor || $whatFor == "default") {
640640
$confirmationTokenResultsBuilder->setValidationSucceed(true);
641641
$confirmationTokenResultsBuilder->withWhatFor($whatFor);
642+
$confirmationTokenResultsBuilder->setTokenId(strval($confirmationTokenModel->id??""));
642643
if ($deleteAfterCheck) {
643644
ConfirmationTokenModel::find($confirmationTokenModel->id)->delete();
644645
}
@@ -790,6 +791,7 @@ public static function checkInvitationToken(string $token, string $whatFor = "de
790791
$invitationResultsBuilder->withUserId($invitationModel->userId);
791792
if (!self::isExpired(DateTime::createFromFormat('Y-m-d H:i:s', $invitationModel->expire_at))) {
792793
if ($invitationModel->whatFor == $whatFor || $whatFor == "default") {
794+
$invitationResultsBuilder->setTokenId(strval($invitationModel->id??""));
793795
$invitationResultsBuilder->setValidationSucceed(true);
794796
$invitationResultsBuilder->withData($invitationModel->data);
795797
$invitationResultsBuilder->withTargetEmail($invitationModel->target_email);

0 commit comments

Comments
 (0)