Merge origin/master
Conflicts: src/java/bdd/PompierMySql.java src/java/com/test/forms/AuthentifForm.java src/java/com/test/forms/NouveauPompForm.java src/java/com/test/servlets/authentifServlet.java
This commit is contained in:
commit
071b58ab9d
@ -50,21 +50,24 @@ public class PompierMySql {
|
|||||||
ResultSet resultQ = null;
|
ResultSet resultQ = null;
|
||||||
resultQ = stmt.executeQuery("SELECT * FROM pompier");
|
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.getInt("idCaserne"),
|
resultQ.getInt("idCaserne"),
|
||||||
resultQ.getString("nom"),
|
resultQ.getString("nom"),
|
||||||
resultQ.getString("prenom"),
|
resultQ.getString("prenom"),
|
||||||
resultQ.getInt("statut"),
|
resultQ.getInt("statut"),
|
||||||
|
resultQ.getInt("typePers"),
|
||||||
resultQ.getString("mail"),
|
resultQ.getString("mail"),
|
||||||
resultQ.getString("login"),
|
resultQ.getString("login"),
|
||||||
resultQ.getString("mdp"),
|
resultQ.getString("mdp"),
|
||||||
resultQ.getInt("adrNo"),
|
resultQ.getString("adresse"),
|
||||||
resultQ.getString("adrRue"),
|
resultQ.getString("cp"),
|
||||||
resultQ.getString("adrCP"),
|
resultQ.getString("ville"),
|
||||||
resultQ.getString("adrVille"),
|
resultQ.getString("bip"),
|
||||||
|
resultQ.getInt("nbGardes"),
|
||||||
resultQ.getInt("grade"),
|
resultQ.getInt("grade"),
|
||||||
resultQ.getString("commentaire")
|
resultQ.getString("commentaire")
|
||||||
);
|
resultQ.getInt("idEmployeur")
|
||||||
|
);
|
||||||
lesPompiers.add(unPompier);
|
lesPompiers.add(unPompier);
|
||||||
}
|
}
|
||||||
resultQ.close();
|
resultQ.close();
|
||||||
@ -79,47 +82,6 @@ public class PompierMySql {
|
|||||||
return lesPompiers;
|
return lesPompiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creation du pompier passé en paramètre dans la table pompier Requête non
|
|
||||||
* préparée
|
|
||||||
*
|
|
||||||
* @param p objet de type Pompier (sans identifiant)
|
|
||||||
* @return int : id du Pompier créé
|
|
||||||
*/
|
|
||||||
public int create(Pompier p) {
|
|
||||||
int id = -1;
|
|
||||||
try {
|
|
||||||
Statement stmt = theConnection.createStatement();
|
|
||||||
int status = stmt.executeUpdate(
|
|
||||||
"INSERT INTO pompier (idCaserne, nom, prenom, statut, mail, login, mdp, adrNo, adrRue, adrCP, adrVille, grade) "
|
|
||||||
+ "VALUES ('" + p.getIdCaserne() + "', '"
|
|
||||||
+ p.getNom() + "', '"
|
|
||||||
+ p.getPrenom() + "', '"
|
|
||||||
+ p.getStatut() + "', "
|
|
||||||
+ p.getMail() + ", '"
|
|
||||||
+ p.getLogin() + ", '"
|
|
||||||
+ p.getMdp() + ", '"
|
|
||||||
+ p.getAdrNo() + ", '"
|
|
||||||
+ p.getAdrRue() + "', '"
|
|
||||||
+ p.getAdrCP() + "', '"
|
|
||||||
+ p.getAdrVille() + "', '"
|
|
||||||
+ p.getGrade() + "' );",
|
|
||||||
Statement.RETURN_GENERATED_KEYS);
|
|
||||||
|
|
||||||
// Recherche de l'identifiant du pompier créé
|
|
||||||
if (status > 0) {
|
|
||||||
ResultSet result = stmt.getGeneratedKeys();
|
|
||||||
if (result.first()) {
|
|
||||||
id = result.getInt(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
System.out.println("SQLException : " + ex.getMessage());
|
|
||||||
System.out.println("SQLState : " + ex.getSQLState());
|
|
||||||
System.out.println("Code erreur : " + ex.getErrorCode());
|
|
||||||
}
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creation du pompier passé en paramètre dans la table pompier Requête
|
* Creation du pompier passé en paramètre dans la table pompier Requête
|
||||||
@ -132,7 +94,7 @@ public class PompierMySql {
|
|||||||
int id = -1;
|
int id = -1;
|
||||||
try {
|
try {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
String sql = "INSERT INTO pompier(idCaserne, nom, prenom, statut, mail, login, mdp, adrNo, adrRue, adrCP, adrVille, grade) "
|
String sql = "INSERT INTO pompier(idCaserne, nom, prenom, statut, typePers, mail, login, mdp, adresse, cp, ville, bip, nbGardes, grade, commentaire, idEmployeur) "
|
||||||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?);";
|
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?);";
|
||||||
stmt = theConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
stmt = theConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||||
stmt.setInt(1, p.getIdCaserne());
|
stmt.setInt(1, p.getIdCaserne());
|
||||||
@ -173,21 +135,37 @@ public class PompierMySql {
|
|||||||
String mdp = request.getParameter("ztMDP");
|
String mdp = request.getParameter("ztMDP");
|
||||||
String mdpChiffre = MD5.encode(request.getParameter("ztMDP"));
|
String mdpChiffre = MD5.encode(request.getParameter("ztMDP"));
|
||||||
String sql = "SELECT * FROM pompier WHERE login='" + login + "' AND mdp='" + mdpChiffre + "';";
|
String sql = "SELECT * FROM pompier WHERE login='" + login + "' AND mdp='" + mdpChiffre + "';";
|
||||||
System.out.println("sql:"+sql);
|
System.out.println("sql:" + sql);
|
||||||
try {
|
try {
|
||||||
Statement stmt = theConnection.createStatement();
|
Statement stmt = theConnection.createStatement();
|
||||||
ResultSet resultQ = null;
|
ResultSet resultQ = null;
|
||||||
resultQ = stmt.executeQuery(sql);
|
resultQ = stmt.executeQuery(sql);
|
||||||
resultat = (resultQ.next());
|
resultat = (resultQ.next());
|
||||||
// if(resultat){
|
if (resultat) {
|
||||||
// Pompier lePompier = new Pompier(
|
Pompier lePompier = new Pompier(
|
||||||
// resultQ.getInt("id"),
|
resultQ.getInt("id"),
|
||||||
// resultQ.getInt("idCAserne"),
|
resultQ.getInt("idCaserne"),
|
||||||
//
|
resultQ.getString("nom"),
|
||||||
// );
|
resultQ.getString("prenom"),
|
||||||
// HttpSession maSession = request.getSession();
|
resultQ.getInt("statut"),
|
||||||
// maSession.setAttribute("lePompier", lePompier);
|
resultQ.getInt("typePers"),
|
||||||
// }
|
resultQ.getString("mail"),
|
||||||
|
resultQ.getString("login"),
|
||||||
|
resultQ.getString("mdp"),
|
||||||
|
resultQ.getString("adresse"),
|
||||||
|
resultQ.getString("cp"),
|
||||||
|
resultQ.getString("ville"),
|
||||||
|
resultQ.getString("bip"),
|
||||||
|
resultQ.getInt("nbGardes"),
|
||||||
|
resultQ.getInt("grade"),
|
||||||
|
resultQ.getString("commentaire"),
|
||||||
|
resultQ.getInt("idEmployeur"),
|
||||||
|
|
||||||
|
);
|
||||||
|
HttpSession maSession = request.getSession();
|
||||||
|
maSession.setAttribute("unPompier", lePompier);
|
||||||
|
System.out.println("lePompier :"+ lePompier);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
Logger.getLogger(PompierMySql.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(PompierMySql.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
@ -39,20 +39,16 @@ public class AuthentifForm {
|
|||||||
* @param request
|
* @param request
|
||||||
* @return true is ok, false sinon
|
* @return true is ok, false sinon
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public boolean controlerRole(HttpServletRequest request) {
|
public boolean controlerRole(HttpServletRequest request) {
|
||||||
/* Comparaison entre l'utilisateur saisi et un utilisateur de la base de donées */
|
/* Comparaison entre l'utilisateur saisi et un utilisateur de la base de donées */
|
||||||
// UserP ChefCaserne = new UserP("Michel", "mRANN");
|
// UserP ChefCaserne = new UserP("Michel", "mRANN");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PompierMySql pm = new PompierMySql();
|
PompierMySql pm = new PompierMySql();
|
||||||
boolean resul = pm.isAuthentified(request);
|
boolean resul = pm.isAuthentified(request);
|
||||||
resultat = resul?"":"Pseudo ou mdp incorrect";
|
resultat = resul?"":"Pseudo ou mdp incorrect";
|
||||||
return resul;
|
return resul;
|
||||||
// Mise à jour de l'attribut resultat
|
// Mise à jour de l'attribut resultat
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,19 +47,20 @@ public class NouveauPompForm {
|
|||||||
|
|
||||||
// Creation d'un objet de type Client avec les données transmises
|
// Creation d'un objet de type Client avec les données transmises
|
||||||
|
|
||||||
Pompier unPompier = new Pompier(request.getParameter("id"),
|
Pompier unPompier = new Pompier(
|
||||||
|
request.getParameter("id"),
|
||||||
request.getParameter("idCaserne"),
|
request.getParameter("idCaserne"),
|
||||||
request.getParameter("ztNom"),
|
request.getParameter("nom"),
|
||||||
request.getParameter("ztPrenom"),
|
request.getParameter("prenom"),
|
||||||
request.getParameter("nStatut"),
|
request.getParameter("statut"),
|
||||||
request.getParameter("eMail"),
|
request.getParameter("mail"),
|
||||||
request.getParameter("ztLogin"),
|
request.getParameter("login"),
|
||||||
request.getParameter("ztMDP"),
|
request.getParameter("mdp"),
|
||||||
noRue,
|
noRue,
|
||||||
request.getParameter("ztAdrRue"),
|
request.getParameter("adrRue"),
|
||||||
request.getParameter("ztAdrCP"),
|
request.getParameter("adrCP"),
|
||||||
request.getParameter("ztAdrVille"),
|
request.getParameter("adrVille"),
|
||||||
request.getParameter("nGrade"),
|
request.getParameter("grade"),
|
||||||
request.getParameter("commentaire")
|
request.getParameter("commentaire")
|
||||||
);
|
);
|
||||||
PompierMySql cm = new PompierMySql();
|
PompierMySql cm = new PompierMySql();
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.test.servlets;
|
package com.test.servlets;
|
||||||
|
|
||||||
|
import bdd.PompierMySql;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.http.HttpServlet;
|
import jakarta.servlet.http.HttpServlet;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
@ -57,8 +58,15 @@ public class ModifPompierServlet extends HttpServlet {
|
|||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
PompierMysql PompierMs = new PompierMySql();
|
PompierMySql PompierMs = new PompierMySql();
|
||||||
request.setAttribute("unPompier", PomperMs.readAll());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
processRequest(request, response);
|
processRequest(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,14 +79,16 @@ public class authentifServlet extends HttpServlet {
|
|||||||
AuthentifForm leControle = new AuthentifForm();
|
AuthentifForm leControle = new AuthentifForm();
|
||||||
// Appel de la méthode controlerRole
|
// Appel de la méthode controlerRole
|
||||||
boolean isAuthentified = leControle.controlerRole(request);
|
boolean isAuthentified = leControle.controlerRole(request);
|
||||||
// Création de 2 attributs de requête (isChef et leControle)
|
// Création de 2 attributs de requête (isAuthentified et leControle)
|
||||||
request.setAttribute("isAuthentified", isAuthentified);
|
request.setAttribute("isAuthentified", isAuthentified);
|
||||||
request.setAttribute("controlForm", leControle);
|
request.setAttribute("controlForm", leControle);
|
||||||
HttpSession maSession = request.getSession();
|
HttpSession maSession = request.getSession();
|
||||||
maSession.setAttribute("isAuthentified", true);
|
maSession.setAttribute("isAuthentified", true);
|
||||||
|
|
||||||
// Affichage de la JSP
|
// Affichage de la JSP
|
||||||
if(isAuthentified==true){
|
if(isAuthentified==true){
|
||||||
getServletContext().getRequestDispatcher("/WEB-INF/PompierJSP.jsp")
|
System.out.println("Ma session : "+maSession.getAttribute("unPompier"));
|
||||||
|
getServletContext().getRequestDispatcher("/WEB-INF/ModifPompier.jsp")
|
||||||
.forward(request, response);
|
.forward(request, response);
|
||||||
}else{
|
}else{
|
||||||
getServletContext().getRequestDispatcher("/WEB-INF/accueilJSP.jsp")
|
getServletContext().getRequestDispatcher("/WEB-INF/accueilJSP.jsp")
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<input type="email" name="eMail"/><br /><br/>
|
<input type="email" name="eMail"/><br /><br/>
|
||||||
<label for="ztLogin">Login : </label>
|
<label for="ztLogin">Login : </label>
|
||||||
<input type="text" name="ztLogin" placeholder="Login"/><br /><br/>
|
<input type="text" name="ztLogin" placeholder="Login"/><br /><br/>
|
||||||
<label for="ztMDP">Mot de passe : </label>
|
<label for="ztMDP">Mot de passe : </label>resultQ.getInt("idEmployeur"),
|
||||||
<input type="password" name="ztMDP" placeholder="Mot de passe" /><br /><br />
|
<input type="password" name="ztMDP" placeholder="Mot de passe" /><br /><br />
|
||||||
<label for="nAdrNo">Numéro de rue : </label>
|
<label for="nAdrNo">Numéro de rue : </label>
|
||||||
<input type="number" name="nAdrNo"/><br /><br/>
|
<input type="number" name="nAdrNo"/><br /><br/>
|
||||||
@ -40,8 +40,7 @@
|
|||||||
<input type="text" name="ztAdrVille" placeholder="Ville" /><br /><br/>
|
<input type="text" name="ztAdrVille" placeholder="Ville" /><br /><br/>
|
||||||
<label for="nGrade">Numéro de grade : </label>
|
<label for="nGrade">Numéro de grade : </label>
|
||||||
<input type="number" name="nGrade"/><br /><br/>
|
<input type="number" name="nGrade"/><br /><br/>
|
||||||
<input type="submit" value="="nStatut"/><br /><br/>
|
<input type="submit" value="Valider"/><br /><br/>resultQ.getInt("idEmployeur"),
|
||||||
<label for="eMail">Mail :Valider" />
|
|
||||||
</form>
|
</form>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
@ -18,42 +18,33 @@
|
|||||||
<legend>Fiche Pompier</legend>
|
<legend>Fiche Pompier</legend>
|
||||||
<form name="fPompier" method="POST" action="ModifPompier">
|
<form name="fPompier" method="POST" action="ModifPompier">
|
||||||
<label for="nIdCaserne">Id Caserne : </label>
|
<label for="nIdCaserne">Id Caserne : </label>
|
||||||
<input type="number" name="nIdCaserne" <c:out value="${unPompier.getIdCaserne()}"/><br /><br/>
|
<input type="number" name="nIdCaserne" value="${sessionScope.unPompier.getIdCaserne()}"/><br /><br/>
|
||||||
<label for="ztNom">Nom : </label>
|
<label for="ztNom">Nom : </label>
|
||||||
<input type="text" name="ztNom" placeholder="Nom" <c:out value="${unPompier.getNom()}"/><br /><br/>
|
<input type="text" name="ztNom" placeholder="Nom" value="${unPompier.getNom()}"/><br /><br/>
|
||||||
<label for="ztPrenom">Prénom : </label>
|
<label for="ztPrenom">Prénom : </label>
|
||||||
<input type="text" name="ztPrenom" placeholder="Prénom" <c:out value="${unPompier.getPrenom()}"/><br /><br/>
|
<input type="text" name="ztPrenom" placeholder="Prénom" value="${unPompier.getPrenom()}"/><br /><br/>
|
||||||
<label for="nStatut">Numéro de statut : </label>
|
<label for="nStatut">Numéro de statut : </label>
|
||||||
<input type="number" name="nStatut" <c:out value="${unPompier.getStatut()}"/><br /><br/>
|
<input type="number" name="nStatut" value="${unPompier.getStatut()}"/><br /><br/>
|
||||||
<label for="eMail">Mail : </label>
|
<label for="eMail">Mail : </label>
|
||||||
<input type="email" name="eMail"<c:out value="${unPompier.getAdrmail()}"/> <br /><br/>
|
<input type="email" name="eMail" value="${unPompier.getAdrmail()}"/> <br /><br/>
|
||||||
<label for="ztLogin">Login : </label>
|
<label for="ztLogin">Login : </label>
|
||||||
<input type="text" name="ztLogin" placeholder="Login"<c:out value="${unPompier.getLogin()}"/><br /><br/>
|
<input type="text" name="ztLogin" placeholder="Login" value="${unPompier.getLogin()}"/><br /><br/>
|
||||||
<label for="ztMDP">Mot de passe : </label>
|
<label for="ztMDP">Mot de passe : </label>
|
||||||
<input type="password" name="ztMDP" placeholder="Mot de passe" <c:out value="${unPompier.getMdp()}"/><br /><br />
|
<input type="password" name="ztMDP" placeholder="Mot de passe" value="${unPompier.getMdp()}"/><br /><br />
|
||||||
<label for="nAdrNo">Numéro de rue : </label>
|
<label for="nAdrNo">Numéro de rue : </label>
|
||||||
<input type="number" name="nAdrNo"<br <c:out value="${unPompier.getAdrNo()}"/> <br/>
|
<input type="number" name="nAdrNo"<br <c:out value="${unPompier.getAdrNo()}"/> <br/>
|
||||||
<label for="ztAdrRue">Nom de la rue : </label>
|
<label for="ztAdrRue">Nom de la rue : </label>
|
||||||
<input type="text" name="ztAdrRue" placeholder="Rue" <c:out value="${unPompier.getAdrRue()}"/><br /><br/>
|
<input type="text" name="ztAdrRue" placeholder="Rue" value="${unPompier.getAdrRue()}"/><br /><br/>
|
||||||
<label for="ztAdrCP">Code postal : </label>
|
<label for="ztAdrCP">Code postal : </label>
|
||||||
<input type="text" name="ztAdrCP" placeholder="Code postal" <c:out value="${unPompier.getAdrCP()}"/><br /><br/>
|
<input type="text" name="ztAdrCP" placeholder="Code postal" value="${unPompier.getAdrCP()}"/><br /><br/>
|
||||||
<label for="ztAdrVille">Ville : </label>
|
<label for="ztAdrVille">Ville : </label>
|
||||||
<input type="text" name="ztAdrVille" placeholder="Ville" <c:out value="${unPompier.getAdrVille()}"/><br /><br/>
|
<input type="text" name="ztAdrVille" placeholder="Ville" value="${unPompier.getAdrVille()}"/><br /><br/>
|
||||||
<label for="nGrade">Numéro de grade : </label>
|
<label for="nGrade">Numéro de grade : </label>
|
||||||
<input type="number" name="nGrade"<c:out value="${unPomier.getGrade()}"/></td><br /><br/>
|
<input type="number" name="nGrade" value="${unPomier.getGrade()}"/><br /><br/>
|
||||||
<input type="submit" value="Valider" />
|
<input type="submit" value="Valider" />
|
||||||
</form>
|
</form>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<title>Pompier</title>
|
<title>Pompier</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Hello World!</h1>
|
<h1>Bienvenue</h1>
|
||||||
<a href="ModifPompier"><input type="button" name="btModifP" value="Modifier la fiche pompier"/></a>
|
<a href="ModifPompier"><input type="button" name="btModifP" value="Modifier la fiche pompier"/></a>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user