From 56c98c45ea315e8e10f9eecb4dd0650173d1fa0a Mon Sep 17 00:00:00 2001
From: Yannis Devos <yannis.devos.etu@univ-lille.fr>
Date: Sat, 15 Mar 2025 15:34:39 +0100
Subject: [PATCH] Ajout delete user dans le dao et servlet account, sans
 pouvoir tester

---
 .idea/discord.xml                          | 14 ++++++++++++++
 .idea/libraries/lib1.xml                   | 10 ++++++++++
 .idea/material_theme_project_new.xml       | 10 ++++++++++
 WEB-INF/src/controleurs/DeleteAccount.java |  6 +++++-
 WEB-INF/src/dao/UserDAO.java               | 16 ++++++++++++++++
 s4a021-web-backend.iml                     |  1 +
 6 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 .idea/discord.xml
 create mode 100644 .idea/libraries/lib1.xml
 create mode 100644 .idea/material_theme_project_new.xml

diff --git a/.idea/discord.xml b/.idea/discord.xml
new file mode 100644
index 0000000..104c42f
--- /dev/null
+++ b/.idea/discord.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="DiscordProjectSettings">
+    <option name="show" value="ASK" />
+    <option name="description" value="" />
+    <option name="applicationTheme" value="default" />
+    <option name="iconsTheme" value="default" />
+    <option name="button1Title" value="" />
+    <option name="button1Url" value="" />
+    <option name="button2Title" value="" />
+    <option name="button2Url" value="" />
+    <option name="customApplicationId" value="" />
+  </component>
+</project>
\ No newline at end of file
diff --git a/.idea/libraries/lib1.xml b/.idea/libraries/lib1.xml
new file mode 100644
index 0000000..03aceb1
--- /dev/null
+++ b/.idea/libraries/lib1.xml
@@ -0,0 +1,10 @@
+<component name="libraryTable">
+  <library name="lib1">
+    <CLASSES>
+      <root url="file://$PROJECT_DIR$/../../lib" />
+    </CLASSES>
+    <JAVADOC />
+    <SOURCES />
+    <jarDirectory url="file://$PROJECT_DIR$/../../lib" recursive="false" />
+  </library>
+</component>
\ No newline at end of file
diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml
new file mode 100644
index 0000000..b843ab1
--- /dev/null
+++ b/.idea/material_theme_project_new.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="MaterialThemeProjectNewConfig">
+    <option name="metadata">
+      <MTProjectMetadataState>
+        <option name="userId" value="783852a9:19599df681a:-7fe2" />
+      </MTProjectMetadataState>
+    </option>
+  </component>
+</project>
\ No newline at end of file
diff --git a/WEB-INF/src/controleurs/DeleteAccount.java b/WEB-INF/src/controleurs/DeleteAccount.java
index 29b6bf6..7be4502 100644
--- a/WEB-INF/src/controleurs/DeleteAccount.java
+++ b/WEB-INF/src/controleurs/DeleteAccount.java
@@ -32,7 +32,11 @@ public class DeleteAccount extends HttpServlet {
                 out.println("<link rel=\"stylesheet\" href=\"css/account.css\">");
                 out.println("<title>Account</title>");
                 out.println("</body>");
-                out.println("Your account was successfully deleted !");
+                if (userDao.deleteUser(user.getUserName(), user.getPwd())){
+                    out.println("Your account was successfully deleted !");
+                }else {
+                    out.println("A problem occurred while deleting your account...");
+                }
             }
         } else {
             res.sendRedirect("/s4a021-web-backend/");
diff --git a/WEB-INF/src/dao/UserDAO.java b/WEB-INF/src/dao/UserDAO.java
index d53c633..d6e057e 100644
--- a/WEB-INF/src/dao/UserDAO.java
+++ b/WEB-INF/src/dao/UserDAO.java
@@ -48,6 +48,22 @@ public class UserDAO {
         return false;
     }
 
+    public boolean deleteUser(String username, String password){
+        try{
+            if (isDatabased(getUserByLogs(username, password))) {
+                PreparedStatement stmt = this.con.prepareStatement("DELETE FROM userAccount WHERE username=? AND password=?");
+                stmt.setString(1, username);
+                stmt.setString(2, password);
+
+                stmt.executeUpdate();
+                return true;
+            }
+        }catch (SQLException sqle){
+            sqle.getStackTrace();
+        }
+        return false;
+    }
+
     public List<User> getAllUsers(){
         ArrayList<User> users = new ArrayList<>();
         try{
diff --git a/s4a021-web-backend.iml b/s4a021-web-backend.iml
index 113d0c2..f9d1409 100644
--- a/s4a021-web-backend.iml
+++ b/s4a021-web-backend.iml
@@ -10,5 +10,6 @@
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
     <orderEntry type="library" name="lib" level="project" />
+    <orderEntry type="library" name="lib1" level="project" />
   </component>
 </module>
\ No newline at end of file
-- 
GitLab