From 6aea632ad61ffc31ed8b72e00e1693c1ca3c63fe Mon Sep 17 00:00:00 2001
From: Filippo Bertilotti <filippobertilotti@gmail.com>
Date: Thu, 25 Jul 2024 09:32:34 +0200
Subject: [PATCH] Inizio logica per inserimento database

---
 app/Vola/Services/FakeSSODatabase/FakeSSODatabaseHandler.php |   19 ++++++++++++++-----
 app/Http/Requests/SSOFormRequest.php                         |    2 +-
 app/Http/Controllers/Profiles/ProfilesController.php         |    8 ++++----
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/app/Http/Controllers/Profiles/ProfilesController.php b/app/Http/Controllers/Profiles/ProfilesController.php
index 00457fe..219c211 100644
--- a/app/Http/Controllers/Profiles/ProfilesController.php
+++ b/app/Http/Controllers/Profiles/ProfilesController.php
@@ -83,11 +83,11 @@
     
     public function saveUser(SSOFormRequest $request) {
         $data = $request->all();
-
-        print_r($data);
         //VodafoneUser::save(["Name" => "Paolo", "Surname" => "Test", "EmailAddress" => "paolotest@test.it"]);
-        //$dbHandler = new FakeSSODatabaseHandler;
-        //$databaseHandler->testInserimentoDatabase();
+        $databaseHandler = new FakeSSODatabaseHandler;
+
+        $databaseHandler->insertDataIntoTables($data);
+        
         return view("vodafone_fake_sso.db-create-view");
     }
 
diff --git a/app/Http/Requests/SSOFormRequest.php b/app/Http/Requests/SSOFormRequest.php
index 0231865..27f1e38 100644
--- a/app/Http/Requests/SSOFormRequest.php
+++ b/app/Http/Requests/SSOFormRequest.php
@@ -24,7 +24,7 @@
     public function rules()
     {
         return [
-            'EmailAddress' => 'required|email',
+            'EmailAddress' => 'required|email', //da cambiare con una regular expression?
             'Name' => 'required',
             'Surname' => 'required',
             'sim_1' => 'digits_between:10,10',
diff --git a/app/Vola/Services/FakeSSODatabase/FakeSSODatabaseHandler.php b/app/Vola/Services/FakeSSODatabase/FakeSSODatabaseHandler.php
index 51e47c9..29f383d 100644
--- a/app/Vola/Services/FakeSSODatabase/FakeSSODatabaseHandler.php
+++ b/app/Vola/Services/FakeSSODatabase/FakeSSODatabaseHandler.php
@@ -3,8 +3,13 @@
 
 use Exception;
 use Illuminate\Support\Facades\DB;
+use PDOException;
 
 class FakeSSODatabaseHandler {
+
+    public function __construct() {
+        echo "Loaded class 'FakeSSODatabaseHandler'";
+    }
     
     /*public function insertDataIntoTable(array $data) {
         //usare insert() per inserire il valore nella tabella giusta
@@ -14,12 +19,16 @@
         
     }*/
 
-    public function testInsert() {
+    public function insertDataIntoTables(array $data) {
+        print_r($data["EmailAddress"]);
+
+
         try{
-            DB::insert("insert into fakesso_vodafoneusers (Name, Surname) values (?, ?)", ["CIAO", "CIAONE"]);
-        }catch(Exception $e) {
-            echo $e;
-        }
+            DB::insert("insert into fakesso_vodafoneusers (Name, Surname, EmailAddress) values (?, ?, ?)",
+                        [$data["Name"], $data["Surname"], $data["EmailAddress"]]);
+        }catch(PDOException $e) {
+            echo $e->getMessage();
+        };
     }
 
 

--
Gitblit v1.8.0