Browse Source

Modifications tp4 ok

Clément Krebs 6 years ago
parent
commit
34cec7d48b
4 changed files with 17 additions and 15 deletions
  1. 1 1
      Tp4/adduser.php
  2. 1 0
      Tp4/changepassword.php
  3. 6 14
      Tp4/deleteuser.php
  4. 9 0
      Tp4/models/User.php

+ 1 - 1
Tp4/adduser.php

@@ -1,5 +1,5 @@
 <?php
-    include_once('bdd.php');
+    require_once('models/User.php');
 
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         header('Location: signup.php');

+ 1 - 0
Tp4/changepassword.php

@@ -1,5 +1,6 @@
 <?php
     session_start();
+    require_once('models/User.php');
     if (!isset($_SESSION['login'])){
         header('Location: signin.php');
         exit();

+ 6 - 14
Tp4/deleteuser.php

@@ -1,27 +1,19 @@
 <?php
     session_start();
+    require_once('models/User.php');
     if (!isset($_SESSION['login'])) {
         header('Location: signin.php');
     }
     
 
-    include_once('bdd.php');
     try {
-        $pdo = new PDO(SQL_DSN, SQL_USERNAME, SQL_PASSWORD);
-    }
-    catch (PDOException $e) {
-        $_SESSION['message'] = $e->getMessage();
-        header('Location: signin.php');
+        $user = new User($_SESSION['login']);
+        $user->delete();
+        header('Location: signup.php');
         exit();
     }
-    
-    $req = $pdo->prepare('DELETE FROM Users WHERE login = :login');
-    $req->bindValue(':login', $_SESSION['login']);
-    
-    if ($req->execute()) {
+    catch (PDO $e) {
+        $_SESSION['message'] = $e->getMessage();
         header('Location: signin.php');
         exit();
-    } else {
-        header('Location: welcome.php');
-        exit();
     }

+ 9 - 0
Tp4/models/User.php

@@ -70,4 +70,13 @@
 
       }
 
+      function delete() : void {
+        $pdo = MyPDO::pdo();
+        $req = $pdo->prepare('DELETE FROM Users WHERE login = :login');
+        $req->bindValue(':login', $this->getLogin());
+        if (!$req->execute()) {
+          throw new Exception('Problème requête');
+        }
+      }
+
     }