Skip to content

Commit

Permalink
add token deleter
Browse files Browse the repository at this point in the history
  • Loading branch information
HichemTab-tech committed Jul 29, 2023
1 parent cf6d401 commit f5f5585
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/TokensValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,21 @@ private static function prepareConfig(): void
self::$InvitationBaseUrl = self::$config['InvitationToken']['InvitationBaseUrl'];
}

/**
* @param int $type
* @param string $tokenId
* @return void
*/
private static function deleteToken(int $type, string $tokenId): void
{
if ($type == TokensTypes::AUTHENTICATION_BY_TOKEN || $type == TokensTypes::AUTHENTICATION_BY_COOKIE) {
AuthTokenModel::where('id', $tokenId)->delete();
}
elseif ($type == TokensTypes::CONFIRMATION_CODE) {
ConfirmationTokenModel::where('id', $tokenId)->delete();
}
}

/**
* @param string $userId
* @param integer $type
Expand Down Expand Up @@ -608,6 +623,15 @@ public static function checkAuthTokenOrDie(string $fingerPrint = "", ?string $au
}
}

/**
* @param string $tokenId
* @return void
*/
public static function deleteAuthToken(string $tokenId): void
{
self::deleteToken(TokensTypes::AUTHENTICATION_BY_TOKEN, $tokenId);
}

/**
* @param string $code
* @param string|null $encryptedUserId
Expand Down Expand Up @@ -704,6 +728,15 @@ public static function checkConfirmationUrlParamsFromGET(array $_GET_ARRAY, stri
->build();
}

/**
* @param string $tokenId
* @return void
*/
public static function deleteConfirmationToken(string $tokenId): void
{
self::deleteToken(TokensTypes::CONFIRMATION_CODE, $tokenId);
}

/**
* @param DateTime $expirationDate
* @return bool
Expand Down

0 comments on commit f5f5585

Please sign in to comment.