Merge origin/master

Conflicts:
	web/WEB-INF/AuthentificationJSP.jsp
This commit is contained in:
thomas.millot 2021-10-20 11:11:29 +02:00
parent 2d81cde4a8
commit e5fa228860
6 changed files with 55 additions and 33 deletions

BIN
proj/AP31-Projet1.war Normal file

Binary file not shown.

View File

@ -7,12 +7,17 @@ package bdd;
import com.mysql.cj.xdevapi.Client; import com.mysql.cj.xdevapi.Client;
import com.test.beans.Pompier; 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.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* *
@ -33,7 +38,7 @@ public class PompierMysql {
try { try {
Statement stmt = theConnection.createStatement(); Statement stmt = theConnection.createStatement();
ResultSet resultQ = null; ResultSet resultQ = null;
resultQ = stmt.executeQuery("SELECT * FROM client"); resultQ = stmt.executeQuery("SELECT * FROM pompier");
while (resultQ.next()) { while (resultQ.next()) {
unPompier = new Pompier(resultQ.getInt("id"), unPompier = new Pompier(resultQ.getInt("id"),
resultQ.getString("nom"), resultQ.getString("nom"),
@ -156,4 +161,26 @@ public class PompierMysql {
return id; 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;
}
} }

View File

@ -5,6 +5,7 @@
*/ */
package com.test.forms; package com.test.forms;
import bdd.PompierMysql;
import com.test.beans.User; import com.test.beans.User;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@ -24,16 +25,10 @@ public class AuthentifForm {
this.resultat = resultat; this.resultat = resultat;
} }
public String AuthentifPompier(HttpServletRequest request) { public boolean authentifPompier(HttpServletRequest request)
{
String userSaisi = request.getParameter("ztPseudo"); PompierMysql pms = new PompierMysql();
String mdpSaisi = request.getParameter("ztMDP"); return pms.readPompier(request);
String mdpChiffre = MD5.encode(mdpSaisi);
String sql= "Select login, mdp FROM pompier";
return sql;
} }
} }

View File

@ -74,16 +74,18 @@ public class AuthentifServlet extends HttpServlet {
throws ServletException, IOException { throws ServletException, IOException {
// Création de l'objet leControle de type AuthentifForm // Création de l'objet leControle de type AuthentifForm
AuthentifForm leControle = new AuthentifForm(); AuthentifForm leControle = new AuthentifForm();
// Appel de la méthode controlerAdmin // Appel de la méthode authentifPompier
String isAdmin = leControle.AuthentifPompier(request); if(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") getServletContext().getRequestDispatcher("/WEB-INF/ProfilJSP.jsp")
.forward(request, response); .forward(request, response);
} }
else
{
getServletContext().getRequestDispatcher("/WEB-INF/AuthentificationJSP.jsp")
.forward(request, response);
}
}
/** /**
* Returns a short description of the servlet. * Returns a short description of the servlet.

View File

@ -10,7 +10,7 @@
<!-- Affichage du formulaire si l'utilisateur ne s'est pas encore authentifié --> <!-- Affichage du formulaire si l'utilisateur ne s'est pas encore authentifié -->
<div id="contenu"> <div id="contenu">
<h2>Merci de vous identifier pour acceder aux dossiers</h2> <h2>Merci de vous identifier pour acceder aux dossiers</h2>
<form name="frmIdentification" method="POST" action="Profil"> <form name="frmIdentification" method="POST" action="Authentif">
<c:choose> <c:choose>
<c:when test="${empty param.ztPseudo}"> <c:when test="${empty param.ztPseudo}">
<fieldset><legend>Identification utilisateur</legend> <fieldset><legend>Identification utilisateur</legend>
@ -28,8 +28,6 @@
</fieldset> </fieldset>
</c:when> </c:when>
<c:otherwise> <c:otherwise>
<!-- Si l'utilisateur s'est authentifié,
Affichage du message contenu dans l'objet controlForm de type AuthentifForm -->
<p>${controlForm.getResultat()}</p> <p>${controlForm.getResultat()}</p>
</c:otherwise> </c:otherwise>

View File

@ -5,15 +5,15 @@
<td style='border :0px;'> <td style='border :0px;'>
<fieldset><legend>Coordonnées Pompier</legend> <fieldset><legend>Coordonnées Pompier</legend>
<table> <table>
<tr><th>Nom :<input type="text" name="ztNom" size="20" maxlength="30"></th></tr> <tr><th>Nom : <input type="text" name="ztNom" size="20" maxlength="30"></th></tr>
<tr><th>Prénom :<input type="text" name="ztPrenom" size="20" maxlength="30"></th></tr> <tr><th>Prénom : <input type="text" name="ztPrenom" size="20" maxlength="30"></th></tr>
<tr><th>Adresse :<input type="text" name="ztAdr" size="20" maxlength="30"></th></tr> <tr><th>Adresse : <input type="text" name="ztAdr" size="20" maxlength="30"></th></tr>
<tr><th>Ville :<input type="text"name="ztVille" size="20" maxlength="30"></th></tr> <tr><th>Ville : <input type="text"name="ztVille" size="20" maxlength="30"></th></tr>
<tr><th>Code postal :<input type="text" name="ztCp" size="20" maxlength="30"></th></tr> <tr><th>Code postal : <input type="text" name="ztCp" size="20" maxlength="30"></th></tr>
<tr><th>Téléphone :<input type="text" name="ztTel" size="20" maxlength="30"></th></tr> <tr><th>Téléphone : <input type="text" name="ztTel" size="20" maxlength="30"></th></tr>
<tr><th>Mail :<input type="text" name="ztMail" size="20" maxlength="30"></th></tr> <tr><th>Mail : <input type="text" name="ztMail" size="20" maxlength="30"></th></tr>
<tr><th>Statut :<input type="text" name="ztStatut" size="20" maxlength="30"></th></tr> <tr><th>Statut : <input type="text" name="ztStatut" size="20" maxlength="30"></th></tr>
<tr><th>Grade :<input type="text" name="ztGrade" size="20" maxlength="30"></th></tr> <tr><th>Grade : <input type="text" name="ztGrade" size="20" maxlength="30"></th></tr>
</table> </table>
</fieldset> </fieldset>
<fieldset><legend>Coordonnées Employeur</legend> <fieldset><legend>Coordonnées Employeur</legend>