From 7146e93c75c6215af79fbfe523b7da0e339ec64a Mon Sep 17 00:00:00 2001
From: Filippo Bertilotti <filippobertilotti@gmail.com>
Date: Wed, 09 Oct 2024 12:01:55 +0200
Subject: [PATCH] Merge branch 'main' of https://blit.dubbidigitali.it/r/~fbertilotti/fakesso

---
 app/Vola/Services/VolaFakeHTTPResponder/VolaFakeHTTPResponder.php |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/app/Vola/Services/VolaFakeHTTPResponder/VolaFakeHTTPResponder.php b/app/Vola/Services/VolaFakeHTTPResponder/VolaFakeHTTPResponder.php
index a0cd65e..6598289 100644
--- a/app/Vola/Services/VolaFakeHTTPResponder/VolaFakeHTTPResponder.php
+++ b/app/Vola/Services/VolaFakeHTTPResponder/VolaFakeHTTPResponder.php
@@ -2,6 +2,7 @@
 
 namespace App\Vola\Services\VolaFakeHTTPResponder;
 
+use App\Models\VodafoneUser;
 use App\Vola\Classes\Utils;
 use Cookie;
 use GuzzleHttp\Promise\RejectedPromise;
@@ -15,9 +16,14 @@
     public array $data;
     private array $xmlResponses;
 
+    protected string $pathTemplateFolderLegacy;
+    protected string $pathTemplateFolderPicasso;
+
     public function __construct()
     {
         $this->xmlResponses = config('devtools.fake_sso_profiles');
+        $this->pathTemplateFolderLegacy = 'vodafone_fake_sso.response_templates.legacy';
+        $this->pathTemplateFolderPicasso = 'vodafone_fake_sso.response_templates.picasso';
     }
 
     public function getModelBasedResponses(Request $request): array
@@ -27,7 +33,10 @@
 
         if (isset($profile)) {
 
-            $responseContent["data"] = 'test. funziono ma le logiche non sono state ancora implementate';
+            $uriParts = explode("?", $request->url());
+            $method = Str::afterLast($uriParts[0], "/");
+
+            $responseContent["data"] = $this->fillXmlResponses($method, $profile, $picassoRequest);
             $responseContent["status"] = 200;
             \RequestLogger::logProcessedRequest($request, $responseContent, (($picassoRequest) ? 'Picasso' : 'SSO Legacy') );
             return $responseContent;
@@ -40,6 +49,15 @@
             ];
         }
 
+    }
+
+    public function fillXMLResponses(string $method, string $profile, bool $picasso): string
+    {
+        $user = VodafoneUser::where(['id' => $profile])->first();
+        //arguments
+        $viewFolder = ($picasso) ? $this->pathTemplateFolderPicasso : $this->pathTemplateFolderLegacy;
+        $view = $viewFolder . "." . $method;
+        return view($view, ['user' => $user])->render(); //views/response_templates/legacy/*.blade.php ?? *.xml
     }
 
     public function getResponses(Request $request, $selectedUser, $picasso = false): string|array
@@ -165,9 +183,9 @@
             case 'no-method-on-user':
                 return 'This method response is not set for this user. Check this server database.';
             case 'no-method':
-                return 'Couldnt detect requested method. Check your request url.';
+                return 'Couldnt identify requested method. Check your request url.';
             default:
-                return 'Couldnt detect proper response.';
+                return 'Couldnt identify proper response.';
         }
     }
 

--
Gitblit v1.8.0