From b2e34ef85db1fe63e0fa1ef0b65f5334e81888c6 Mon Sep 17 00:00:00 2001 From: HichemTab Date: Fri, 12 May 2023 18:37:23 +0100 Subject: [PATCH] fix url handling --- .idea/codeception.xml | 9 ++ .idea/php.xml | 51 +++++--- .idea/phpspec.xml | 9 ++ .idea/phpunit.xml | 3 + .idea/tokens-validation.iml | 48 +++++++- composer.json | 1 - composer.lock | 109 +----------------- index.php | 28 ++--- .../Confirmation/ConfirmationUrlBuilder.php | 19 +-- .../Invitation/InvitationUrlBuilder.php | 15 ++- 10 files changed, 132 insertions(+), 160 deletions(-) diff --git a/.idea/codeception.xml b/.idea/codeception.xml index 70e3d14..fb995da 100644 --- a/.idea/codeception.xml +++ b/.idea/codeception.xml @@ -12,6 +12,15 @@ + + + + + + diff --git a/.idea/php.xml b/.idea/php.xml index f859828..d5591cb 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -12,38 +12,53 @@ - - - - - - - - - - - + + + + + - - - - - - + + + + + + + + - + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/phpspec.xml b/.idea/phpspec.xml index c7cfbc2..dac988c 100644 --- a/.idea/phpspec.xml +++ b/.idea/phpspec.xml @@ -11,6 +11,15 @@ + + + + + + \ No newline at end of file diff --git a/.idea/phpunit.xml b/.idea/phpunit.xml index 84ebdd2..763fbe3 100644 --- a/.idea/phpunit.xml +++ b/.idea/phpunit.xml @@ -5,6 +5,9 @@ diff --git a/.idea/tokens-validation.iml b/.idea/tokens-validation.iml index d4fcfb0..b7dbf93 100644 --- a/.idea/tokens-validation.iml +++ b/.idea/tokens-validation.iml @@ -5,7 +5,53 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/composer.json b/composer.json index c601731..06d6ff4 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,6 @@ "illuminate/database": "^9.52", "illuminate/events": "^9.52", "illuminate/container": "^9.52", - "jwage/purl": "^0.0.9", "defuse/php-encryption": "^2.3", "illuminate/http": "^9.52" }, diff --git a/composer.lock b/composer.lock index 586b94a..46af3de 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "841f8babd5097c0b9335c87fca5ddb06", + "content-hash": "2736ba94cacdd46110bbd1a9fd50e753", "packages": [ { "name": "brick/math", @@ -1097,113 +1097,6 @@ }, "time": "2023-04-04T18:35:58+00:00" }, - { - "name": "jeremykendall/php-domain-parser", - "version": "1.4.2", - "source": { - "type": "git", - "url": "https://github.com/jeremykendall/php-domain-parser.git", - "reference": "add2b07755ab1d2543a383bd78fbe031c6377f9a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/jeremykendall/php-domain-parser/zipball/add2b07755ab1d2543a383bd78fbe031c6377f9a", - "reference": "add2b07755ab1d2543a383bd78fbe031c6377f9a", - "shasum": "" - }, - "require": { - "ext-curl": "*", - "php": ">=5.3.0" - }, - "require-dev": { - "mikey179/vfsstream": "1.2.*", - "phpunit/phpunit": "4.*" - }, - "bin": [ - "bin/parse", - "bin/pdp-psl" - ], - "type": "library", - "autoload": { - "files": [ - "library/mb-parse-url.php" - ], - "psr-0": { - "Pdp\\": "library/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jeremy Kendall", - "homepage": "http://about.me/jeremykendall", - "role": "Developer" - } - ], - "description": "Public Suffix List based URL parsing implemented in PHP.", - "keywords": [ - "Public Suffix List", - "domain parsing", - "url parsing" - ], - "support": { - "issues": "https://github.com/jeremykendall/php-domain-parser/issues", - "source": "https://github.com/jeremykendall/php-domain-parser/tree/develop" - }, - "time": "2014-07-21T15:23:19+00:00" - }, - { - "name": "jwage/purl", - "version": "v0.0.9", - "source": { - "type": "git", - "url": "https://github.com/jwage/purl.git", - "reference": "60e2055531941aae6eacb1b513bbb2fc75743f91" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/jwage/purl/zipball/60e2055531941aae6eacb1b513bbb2fc75743f91", - "reference": "60e2055531941aae6eacb1b513bbb2fc75743f91", - "shasum": "" - }, - "require": { - "jeremykendall/php-domain-parser": "^1.3.1", - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8|^5.5|^6.5|^7.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Purl\\": "src/Purl" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jonathan H. Wage", - "email": "jonwage@gmail.com" - } - ], - "description": "URL Manipulation for PHP 5.3", - "homepage": "http://github.com/jwage/purl", - "keywords": [ - "manipulation", - "url" - ], - "support": { - "issues": "https://github.com/jwage/purl/issues", - "source": "https://github.com/jwage/purl/tree/master" - }, - "time": "2018-05-17T15:22:38+00:00" - }, { "name": "nesbot/carbon", "version": "2.66.0", diff --git a/index.php b/index.php index 40ceb55..8af2a14 100644 --- a/index.php +++ b/index.php @@ -8,18 +8,17 @@ TokensValidation::setFeatures([ 'AuthTokens', 'ConfirmationToken', - 'InvitationsTokens' ]); TokensValidation::setInvitationTokenExpirationDelay(60*60*24); TokensValidation::$InvitationBaseUrl = "http://localhost/invitations"; -TokensValidation::$InvitationTokenGenerator = MyInvitationTokenGenerator::class; -TokensValidation::$InvitationUrlBuilder = MyInvitationUrlBuilder::class; +/*TokensValidation::$InvitationTokenGenerator = MyInvitationTokenGenerator::class; +TokensValidation::$InvitationUrlBuilder = MyInvitationUrlBuilder::class;*/ TokensValidation::prepare(); -echo "
";
-/*print_r(TokensValidation::$config);
+/*echo "
";
+print_r(TokensValidation::$config);
 die();*/
 /*try {
     $inv = TokensValidation::createInvitation(
@@ -37,10 +36,9 @@
     $inv->getUrl(),
     $inv
 ]);*/
-
-try {
+/*try {
     $inv = TokensValidation::checkInvitationUrl(
-        url: "http://localhost/invitations?c=TQrI32ZN7f7gKF7yPtmT8mQLp",
+        url: "http://localhost/invitations?c=e6dXr7kg5aPO4Olz5RlpXHiww",
         whatFor: "administration",
     );
 
@@ -51,12 +49,12 @@
 }
 print_r([
     $inv
-]);
+]);*/
 
 //verify the data entered by the user.
 
 
-$invitation = TokensValidation::checkInvitationToken(
+/*$invitation = TokensValidation::checkInvitationToken(
     token: $_GET['token'],
     whatFor: "administration",
     thenAccept: true
@@ -64,17 +62,11 @@
 
 if (!$invitation->isValidationSucceed()) {
     die("INVITATION_INVALID");
-}
+}*/
 
 //insert the data entered by the user.
 //performe some actions
 echo "invitation accepted";
 
-?>
+die();
 
-
- - - - -
diff --git a/src/Actions/Confirmation/ConfirmationUrlBuilder.php b/src/Actions/Confirmation/ConfirmationUrlBuilder.php index 6e864c0..cd597a2 100644 --- a/src/Actions/Confirmation/ConfirmationUrlBuilder.php +++ b/src/Actions/Confirmation/ConfirmationUrlBuilder.php @@ -3,7 +3,6 @@ namespace HichemtabTech\TokensValidation\Actions\Confirmation; use HichemtabTech\TokensValidation\Model\Confirmation\ConfirmationToken; -use Purl\Url; /** * @@ -30,10 +29,13 @@ public function __construct() */ public function getUrl(ConfirmationToken $confirmationToken, string $baseUrl): string { - $url = new Url($baseUrl); - $url->query->set("u", $confirmationToken->getUserId());// for userId - $url->query->set("c", $confirmationToken->getContent());// for Code - return $url->getUrl(); + $p = parse_url($baseUrl); + parse_str($p['query']??"", $r); + $r['u'] = $confirmationToken->getUserId(); + $r['c'] = $confirmationToken->getContent(); + $q = http_build_query($r); + return $p['scheme'] . '://' . $p['host'] . $p['path'] + . (!empty($q) ? '?' . $q : ''); } /** @@ -42,10 +44,11 @@ public function getUrl(ConfirmationToken $confirmationToken, string $baseUrl): s */ public function getUserIdAndTokenFromUrl(string $url): UserIdAndToken { - $url = new Url($url); + $p = parse_url($url); + parse_str($p['query']??"", $r); return UserIdAndToken::builder() - ->setUserId($url->query->get("u")) - ->setToken($url->query->get("c")) + ->setUserId($r["u"]??"") + ->setToken($r["c"]??"") ->build(); } diff --git a/src/Actions/Invitation/InvitationUrlBuilder.php b/src/Actions/Invitation/InvitationUrlBuilder.php index 66c6356..c25a3d9 100644 --- a/src/Actions/Invitation/InvitationUrlBuilder.php +++ b/src/Actions/Invitation/InvitationUrlBuilder.php @@ -4,7 +4,6 @@ use HichemtabTech\TokensValidation\Model\Invitation\Invitation; use Illuminate\Http\Request; -use Purl\Url; class InvitationUrlBuilder { @@ -15,9 +14,12 @@ class InvitationUrlBuilder */ public function getUrl(Invitation $invitation, string $baseUrl): string { - $url = new Url($baseUrl); - $url->query->set("c", $invitation->getContent());// for Code - return $url->getUrl(); + $p = parse_url($baseUrl); + parse_str($p['query']??"", $r); + $r['c'] = $invitation->getContent(); + $q = http_build_query($r); + return $p['scheme'] . '://' . $p['host'] . $p['path'] + . (!empty($q) ? '?' . $q : ''); } /** @@ -26,8 +28,9 @@ public function getUrl(Invitation $invitation, string $baseUrl): string */ public function getTokenFromUrl(string $url): string { - $url = new Url($url); - return $url->query->get("c"); + $p = parse_url($url); + parse_str($p['query']??"", $r); + return $r['c']??""; } /**