diff --git a/proj/AP31-Projet1.war b/proj/AP31-Projet1.war new file mode 100644 index 0000000..10cc4c2 Binary files /dev/null and b/proj/AP31-Projet1.war differ diff --git a/src/java/bdd/PompierMysql.java b/src/java/bdd/PompierMysql.java index 52f1006..906813a 100644 --- a/src/java/bdd/PompierMysql.java +++ b/src/java/bdd/PompierMysql.java @@ -7,12 +7,17 @@ package bdd; import com.mysql.cj.xdevapi.Client; import com.test.beans.Pompier; +import com.test.forms.MD5; +import jakarta.servlet.http.HttpServletRequest; +import java.net.http.HttpRequest; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -33,7 +38,7 @@ public class PompierMysql { try { Statement stmt = theConnection.createStatement(); ResultSet resultQ = null; - resultQ = stmt.executeQuery("SELECT * FROM client"); + resultQ = stmt.executeQuery("SELECT * FROM pompier"); while (resultQ.next()) { unPompier = new Pompier(resultQ.getInt("id"), resultQ.getString("nom"), @@ -155,5 +160,27 @@ public class PompierMysql { } return id; } - + + public boolean readPompier(HttpServletRequest request) { + boolean reponse = false; + Statement stmt; + String userSaisi = request.getParameter("ztPseudo"); + String mdpSaisi = request.getParameter("ztMDP"); + String mdpChiffre = MD5.encode(mdpSaisi); + System.out.println("userSaisi : "+ userSaisi); + System.out.println("mdpSaisi : "+ mdpChiffre); + try { + System.out.println("Select * FROM pompier WHERE login = '"+userSaisi+"' AND mdp = '"+mdpChiffre+"';"); + stmt = theConnection.createStatement(); + ResultSet resultQ = null; + resultQ = stmt.executeQuery("Select * FROM pompier WHERE login = '"+userSaisi+"' AND mdp = '"+mdpChiffre+"';"); + reponse = resultQ.next(); + } catch (SQLException ex) { + Logger.getLogger(PompierMysql.class.getName()).log(Level.SEVERE, null, ex); + } + + return reponse; + + } + } diff --git a/src/java/com/test/forms/AuthentifForm.java b/src/java/com/test/forms/AuthentifForm.java index 997777d..0d1cfab 100644 --- a/src/java/com/test/forms/AuthentifForm.java +++ b/src/java/com/test/forms/AuthentifForm.java @@ -5,6 +5,7 @@ */ package com.test.forms; +import bdd.PompierMysql; import com.test.beans.User; import jakarta.servlet.http.HttpServletRequest; @@ -24,16 +25,10 @@ public class AuthentifForm { this.resultat = resultat; } - public String AuthentifPompier(HttpServletRequest request) { - - String userSaisi = request.getParameter("ztPseudo"); - String mdpSaisi = request.getParameter("ztMDP"); - String mdpChiffre = MD5.encode(mdpSaisi); - - String sql= "Select login, mdp FROM pompier"; - - return sql; - + public boolean authentifPompier(HttpServletRequest request) + { + PompierMysql pms = new PompierMysql(); + return pms.readPompier(request); } } diff --git a/src/java/com/test/servlets/AuthentifServlet.java b/src/java/com/test/servlets/AuthentifServlet.java index 50eec49..0442cf4 100644 --- a/src/java/com/test/servlets/AuthentifServlet.java +++ b/src/java/com/test/servlets/AuthentifServlet.java @@ -73,16 +73,18 @@ public class AuthentifServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Création de l'objet leControle de type AuthentifForm - AuthentifForm leControle = new AuthentifForm(); - // Appel de la méthode controlerAdmin - String isAdmin = leControle.AuthentifPompier(request); - // Création de 2 attributs de requête (isAdmin et leControle) - request.setAttribute("isAdmin", isAdmin); - request.setAttribute("controlForm", leControle); - - // Affichage de la JSP - getServletContext().getRequestDispatcher("/WEB-INF/ProfilJSP.jsp") + AuthentifForm leControle = new AuthentifForm(); + // Appel de la méthode authentifPompier + if(leControle.authentifPompier(request)) + { + getServletContext().getRequestDispatcher("/WEB-INF/ProfilJSP.jsp") + .forward(request, response); + } + else + { + getServletContext().getRequestDispatcher("/WEB-INF/AuthentificationJSP.jsp") .forward(request, response); + } } /** diff --git a/web/WEB-INF/AuthentificationJSP.jsp b/web/WEB-INF/AuthentificationJSP.jsp index c83f4d3..5822fb8 100644 --- a/web/WEB-INF/AuthentificationJSP.jsp +++ b/web/WEB-INF/AuthentificationJSP.jsp @@ -10,7 +10,7 @@