Tidy a bit the files structure.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 9 Jan 2018 21:14:39 +0000 (22:14 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 9 Jan 2018 21:14:39 +0000 (22:14 +0100)
Workaround a bug in variable arguments number in the DB class.

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
18 files changed:
footer.html [deleted file]
formlogin.php [deleted file]
includes/account.php [moved from account.php with 100% similarity]
includes/booking.php [moved from booking.php with 100% similarity]
includes/config.php [moved from config.php with 100% similarity]
includes/footer.html [new file with mode: 0644]
includes/formlogin.php [new file with mode: 0644]
includes/formregister.php [new file with mode: 0644]
includes/header.html [moved from header.html with 76% similarity]
includes/header.php [moved from header.php with 100% similarity]
includes/home.php [moved from home.php with 78% similarity]
includes/login.php [new file with mode: 0644]
includes/register.php [new file with mode: 0644]
includes/search.php [moved from search.php with 100% similarity]
index.php
lib/db.php
login.php [deleted file]
register.php [deleted file]

diff --git a/footer.html b/footer.html
deleted file mode 100644 (file)
index e06db19..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<div id="footer">
-    &copy;2018 - <a href="https://piment-noir.org">Piment Noir</a>
-</div>
-</body>
-</html>
diff --git a/formlogin.php b/formlogin.php
deleted file mode 100644 (file)
index f3b8765..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-$form_email = filter_input(INPUT_POST, "email", FILTER_VALIDATE_EMAIL);
-$form_password = filter_input(INPUT_POST, "password", FILTER_SANITIZE_STRING);
-
-if (!$form_email) {
-    echo "The email is not valid";
-} else {
-    $sql_pquery = "select count() from Client where EmailCI = ?";
-}
-
-?>
similarity index 100%
rename from account.php
rename to includes/account.php
similarity index 100%
rename from booking.php
rename to includes/booking.php
similarity index 100%
rename from config.php
rename to includes/config.php
diff --git a/includes/footer.html b/includes/footer.html
new file mode 100644 (file)
index 0000000..733dbb9
--- /dev/null
@@ -0,0 +1,5 @@
+<div id="footer">
+    &copy;2018 - Made by <a href="https://piment-noir.org">Piment Noir</a>
+</div>
+</body>
+</html>
diff --git a/includes/formlogin.php b/includes/formlogin.php
new file mode 100644 (file)
index 0000000..8da2e2c
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+$form_email = filter_input(INPUT_POST, "email", FILTER_VALIDATE_EMAIL);
+$form_password = filter_input(INPUT_POST, "password", FILTER_SANITIZE_STRING);
+
+if (!$form_email) {
+    echo "The email is not valid <br>";
+} else {
+    $sql_pquery = "select count(NumCI) from CLIENTS where EmailCI = ?";
+
+    echo "This email do not belong to a registred client, please register first <br>";
+
+    if (password_verify($form_password, $stored_password)) {
+
+    }
+}
+?>
diff --git a/includes/formregister.php b/includes/formregister.php
new file mode 100644 (file)
index 0000000..53b5f6d
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+$form_name = filter_input(INPUT_POST, "name", FILTER_SANITIZE_STRING);
+$form_firstname = filter_input(INPUT_POST, "firstname", FILTER_SANITIZE_STRING);
+$form_numstreet = filter_input(INPUT_POST, "numstreet", FILTER_VALIDATE_INT);
+$form_street = filter_input(INPUT_POST, "street", FILTER_SANITIZE_STRING);
+$form_postalcode = filter_input(INPUT_POST, "postalcode", FILTER_VALIDATE_INT);
+$form_town = filter_input(INPUT_POST, "postalcode", FILTER_SANITIZE_STRING);
+$form_email = filter_input(INPUT_POST, "email", FILTER_VALIDATE_EMAIL);
+$form_password = filter_input(INPUT_POST, "password", FILTER_SANITIZE_STRING);
+$form_confirmpassword = filter_input(INPUT_POST, "confirmpassword", FILTER_SANITIZE_STRING);
+
+$error_numstreet = false;
+$error_postalcode = false;
+$error_email = false;
+$error_password = false;
+
+if (!$form_numstreet) {
+    echo "The street number is not valid <br>" ;
+    $error_numstreet = true;
+}
+if (!$form_postalcode) {
+    echo "The postal code is not valid <br>";
+    $error_postalcode = true;
+}
+if (!$form_email) {
+    echo "The email is not valid <br>";
+    $error_email = true;
+}
+if (strcmp($form_password, $form_confirmpassword) === 0) {
+    echo "Password do not match <br>";
+    $error_password = true;
+}
+
+if (!empty($form_name) && !empty($form_firstname) && !empty($form_numstreet) && !empty($form_street) &&
+    !empty($form_postalcode) && !empty($form_town) && !empty($form_email) && !empty($form_password)){
+    global $connection;
+    $sql_pquery = "select count(NumCl) from CLIENTS where EmailCl = ?";
+    $stmt = $connection->prepare_query($sql_pquery);
+    $stmt->bind_param("s", $form_email);
+    //$connection->prepared_query_bind_param("s", $form_email);
+    $connection->run_prepared_query();
+    $connection->close_prepared_query();
+}
+?>
similarity index 76%
rename from header.html
rename to includes/header.html
index 5721c7d0efc57e3c54306763ec782f931df78f76..602e0cfeaedd24b6b393affe5cae621cebc6ae53 100644 (file)
@@ -4,7 +4,7 @@
 <head>
 <title>Air Polytech</title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<link href="https://fonts.googleapis.com/css?family=Encode+Sans+Semi+Condensed" rel="stylesheet">
+<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Encode+Sans+Semi+Condensed">
 <link rel="stylesheet" type="text/css" href="styles/airpolytech.css" />
 </head>
 <body>
similarity index 100%
rename from header.php
rename to includes/header.php
similarity index 78%
rename from home.php
rename to includes/home.php
index 5499ba92e1cc09cdd90eea58e6d1ca8772fb891d..cc378a2836c3dfdd0c389e4e20ea29e7407c54ef 100644 (file)
--- a/home.php
@@ -1,9 +1,9 @@
 <?php
+
 function home()
 {
-    global $configs;
+    global $connection;
 
-    $connection = new CustomDB($configs['host'], $configs['username'], $configs['password'], $configs['database']);
     $requete = "SELECT NumCl, NomCl, CodePosteCl, VilleCl FROM CLIENTS";
     $result = $connection->query($requete);
     echo "<table border=1>\n";
@@ -17,7 +17,6 @@ function home()
     }
     echo "</table>\n";
     $result->close();
-    $connection->close();
 }
 
 home();
diff --git a/includes/login.php b/includes/login.php
new file mode 100644 (file)
index 0000000..19c74da
--- /dev/null
@@ -0,0 +1,6 @@
+<form action="index.php" method="post">
+ <input type="hidden" name="form" value="login" />
+ <p> Email : <input type="text" name="email" /> </p>
+ <p> Mot de passe : <input type="password" name="password" /> </p>
+ <p> <input type="submit" value="Valider"> </p>
+</form>
diff --git a/includes/register.php b/includes/register.php
new file mode 100644 (file)
index 0000000..72b9884
--- /dev/null
@@ -0,0 +1,15 @@
+<form action="index.php" method="post">
+ <input type="hidden" name="form" value="register" />
+ <p> Nom  : <input type="text" name="name" /> </p>
+ <p> Pre&#769;nom : <input type="text" name="firstname" /> </p>
+ <p> Adresse : </p>
+ <p> Nume&#769;ro de rue : <input type="text" name="numstreet" />
+     Rue : <input type="text" name="street" />
+     Code postal : <input type="text" name="postalcode" />
+     Ville : <input type="text" name="town" />
+ </p>
+ <p> Email : <input type="text" name="email" /> </p>
+ <p> Mot de passe : <input type="password" name="password" /> </p>
+ <p> Confirnation du mot de passe : <input type="password" name="confirmpassword" /> </p>
+ <p> <input type="submit" value="Valider"> </p>
+</form>
similarity index 100%
rename from search.php
rename to includes/search.php
index 9d22f3e15361790b8c2fe89561b28cc88ebd0cf2..8bceb64bb6702c58fa45b66bb7f4ea744d6415d5 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,5 +1,5 @@
 <?php
-require('header.php');
+require('includes/header.php');
 
 include('lib/db.php');
 include('lib/utils.php');
@@ -9,6 +9,8 @@ include('lib/utils.php');
  */
 session_start();
 
+$connection = new CustomDB($configs['host'], $configs['username'], $configs['password'], $configs['database']);
+
 $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_URL);
 $isPage = true;
 if (!isset($page)) {
@@ -40,17 +42,17 @@ function get_action_type() {
     }
 }
 
-function get_url_action() {
+function get_url_action($action_type) {
     global $page, $form;
 
-    if (get_action_type() === "page") {
+    if ($action_type === "page") {
         return $page;
-    } elseif (get_action_type() === "form") {
+    } elseif ($action_type === "form") {
         return $form;
-    } elseif (get_action_type() === "empty") {
+    } elseif ($action_type === "empty") {
         return "";
-    } elseif (get_action_type() === "unknown") {
-        die('Cannot get a valid action from URL parameters');
+    } elseif ($action_type === "unknown") {
+        die('Cannot get a valid action from URL parameters or form fields');
     }
 }
 
@@ -74,36 +76,42 @@ function validate_url_action($action_name)
     return $configs['actions'][0];
 }
 
-function display_action($action_name)
+function display_action($action_name, $action_type)
 {
-    global $configs, $isPage, $isForm;
+    global $configs;
+    $includes_rpath = 'includes';
 
     $found_action = false;
     foreach ($configs['actions'] as $action) {
         if (strcmp($action_name, $action) === 0) {
             // HTTP GET case
-            if (get_action_type() === "page" || get_action_type() === "empty") {
-                include($action . ".php");
+            if ($action_type === "page" || $action_type === "empty") {
+                include($includes_rpath . "/" . $action . ".php");
             // HTTP POST case
-            } elseif (get_action_type() === "form") {
-                include("form" . $action . ".php");
+            } elseif ($action_type === "form") {
+                include($includes_rpath . "/form" . $action . ".php");
             } else {
-                echo "Unknown error in action displaying";
+                echo "Unknown error in action displaying <br>";
             }
             $found_action = true;
             break;
         }
     }
     if (!$found_action) {
-        echo "Action to display do not exist";
+        echo "Action to display do not exist <br>";
     }
 }
 
-$url_action = get_url_action();
+//password_hash('12345678', PASSWORD_DEFAULT);
+
+$action_type = get_action_type();
+$url_action = get_url_action($action_type);
 $action = validate_url_action($url_action);
-display_action($action);
+display_action($action, $action_type);
+
+$connection->close();
 
 session_destroy();
 
-require('footer.html');
+require('includes/footer.html');
 ?>
index 0f280a459e8efbdbeb55c0de5730481678b6cf9b..b548804c385f586ede81f6ac8f5c73f875d8dc92 100644 (file)
@@ -52,7 +52,7 @@ class CustomDB
     public function query($sql_query)
     {
         if ($this->connected && !($query_result = $this->connection->query($sql_query))) {
-            echo "Fail to execute the SQL query : " . $sql_query;
+            echo "Fail to execute the SQL query : " . $sql_query . "<br>";
         }
         return $query_result;
     }
@@ -68,7 +68,7 @@ class CustomDB
         if ($this->connected && !($this->current_stmt = $this->connection->prepare($this->current_pquery))) {
             // Empty the currently stored prepared query in the failure case
             $this->current_pquery = "";
-            echo "Fail to prepare SQL query : (" . $this->connection->errno . ") " . $this->connection->error . " - " . $this->current_pquery;
+            echo "Fail to prepare SQL query : (" . $this->connection->errno . ") " . $this->connection->error . " - " . $this->current_pquery . "<br>";
         }
         return $this->current_stmt;
     }
@@ -80,9 +80,10 @@ class CustomDB
      */
     public function prepared_query_bind_param(...$params)
     {
+        var_dump($params);
         $rt_val = $this->current_stmt->bind_param($params);
         if (!$rt_val) {
-            echo "Fail to link parameters to SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery;
+            echo "Fail to link parameters to SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery . "<br>";
         }
         return $rt_val;
     }
@@ -95,7 +96,7 @@ class CustomDB
     {
         $rt_val = $this->current_stmt->execute();
         if (!$rt_val) {
-            echo "Fail to execute SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery;
+            echo "Fail to execute SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery . "<br>";
         }
         return $rt_val;
     }
@@ -108,7 +109,7 @@ class CustomDB
     {
         $rt_val = $this->current_stmt->close();
         if (!$rt_val) {
-            echo "Fail to close SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery;
+            echo "Fail to close SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery . "<br>";
         }
         return $rt_val;
     }
diff --git a/login.php b/login.php
deleted file mode 100644 (file)
index e976fc9..0000000
--- a/login.php
+++ /dev/null
@@ -1,6 +0,0 @@
-<form action="index.php" method="post">
- <input type="hidden" name="form" value="login" />
- <p>Email : <input type="text" name="email" /></p>
- <p>Mot de passe : <input type="text" name="password" /></p>
- <p><input type="submit" value="OK"></p>
-</form>
diff --git a/register.php b/register.php
deleted file mode 100644 (file)
index e69de29..0000000