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;
|
||||
resultQ = stmt.executeQuery("SELECT * FROM pompier");
|
||||
while (resultQ.next()) {
|
||||
unPompier = new Pompier(resultQ.getInt("id"),
|
||||
unPompier = new Pompier (resultQ.getInt("id"),
|
||||
resultQ.getInt("idCaserne"),
|
||||
resultQ.getString("nom"),
|
||||
resultQ.getString("prenom"),
|
||||
resultQ.getInt("statut"),
|
||||
resultQ.getInt("typePers"),
|
||||
resultQ.getString("mail"),
|
||||
resultQ.getString("login"),
|
||||
resultQ.getString("mdp"),
|
||||
resultQ.getInt("adrNo"),
|
||||
resultQ.getString("adrRue"),
|
||||
resultQ.getString("adrCP"),
|
||||
resultQ.getString("adrVille"),
|
||||
resultQ.getString("adresse"),
|
||||
resultQ.getString("cp"),
|
||||
resultQ.getString("ville"),
|
||||
resultQ.getString("bip"),
|
||||
resultQ.getInt("nbGardes"),
|
||||
resultQ.getInt("grade"),
|
||||
resultQ.getString("commentaire")
|
||||
);
|
||||
resultQ.getInt("idEmployeur")
|
||||
);
|
||||
lesPompiers.add(unPompier);
|
||||
}
|
||||
resultQ.close();
|
||||
@ -79,47 +82,6 @@ public class PompierMySql {
|
||||
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
|
||||
@ -132,7 +94,7 @@ public class PompierMySql {
|
||||
int id = -1;
|
||||
try {
|
||||
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?);";
|
||||
stmt = theConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||
stmt.setInt(1, p.getIdCaserne());
|
||||
@ -173,21 +135,37 @@ public class PompierMySql {
|
||||
String mdp = request.getParameter("ztMDP");
|
||||
String mdpChiffre = MD5.encode(request.getParameter("ztMDP"));
|
||||
String sql = "SELECT * FROM pompier WHERE login='" + login + "' AND mdp='" + mdpChiffre + "';";
|
||||
System.out.println("sql:"+sql);
|
||||
System.out.println("sql:" + sql);
|
||||
try {
|
||||
Statement stmt = theConnection.createStatement();
|
||||
ResultSet resultQ = null;
|
||||
resultQ = stmt.executeQuery(sql);
|
||||
resultat = (resultQ.next());
|
||||
// if(resultat){
|
||||
// Pompier lePompier = new Pompier(
|
||||
// resultQ.getInt("id"),
|
||||
// resultQ.getInt("idCAserne"),
|
||||
//
|
||||
// );
|
||||
// HttpSession maSession = request.getSession();
|
||||
// maSession.setAttribute("lePompier", lePompier);
|
||||
// }
|
||||
if (resultat) {
|
||||
Pompier lePompier = new Pompier(
|
||||
resultQ.getInt("id"),
|
||||
resultQ.getInt("idCaserne"),
|
||||
resultQ.getString("nom"),
|
||||
resultQ.getString("prenom"),
|
||||
resultQ.getInt("statut"),
|
||||
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) {
|
||||
Logger.getLogger(PompierMySql.class.getName()).log(Level.SEVERE, null, ex);
|
||||
|
@ -39,20 +39,16 @@ public class AuthentifForm {
|
||||
* @param request
|
||||
* @return true is ok, false sinon
|
||||
*/
|
||||
|
||||
public boolean controlerRole(HttpServletRequest request) {
|
||||
/* Comparaison entre l'utilisateur saisi et un utilisateur de la base de donées */
|
||||
// UserP ChefCaserne = new UserP("Michel", "mRANN");
|
||||
|
||||
|
||||
|
||||
PompierMySql pm = new PompierMySql();
|
||||
boolean resul = pm.isAuthentified(request);
|
||||
resultat = resul?"":"Pseudo ou mdp incorrect";
|
||||
return resul;
|
||||
// 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
|
||||
|
||||
Pompier unPompier = new Pompier(request.getParameter("id"),
|
||||
Pompier unPompier = new Pompier(
|
||||
request.getParameter("id"),
|
||||
request.getParameter("idCaserne"),
|
||||
request.getParameter("ztNom"),
|
||||
request.getParameter("ztPrenom"),
|
||||
request.getParameter("nStatut"),
|
||||
request.getParameter("eMail"),
|
||||
request.getParameter("ztLogin"),
|
||||
request.getParameter("ztMDP"),
|
||||
request.getParameter("nom"),
|
||||
request.getParameter("prenom"),
|
||||
request.getParameter("statut"),
|
||||
request.getParameter("mail"),
|
||||
request.getParameter("login"),
|
||||
request.getParameter("mdp"),
|
||||
noRue,
|
||||
request.getParameter("ztAdrRue"),
|
||||
request.getParameter("ztAdrCP"),
|
||||
request.getParameter("ztAdrVille"),
|
||||
request.getParameter("nGrade"),
|
||||
request.getParameter("adrRue"),
|
||||
request.getParameter("adrCP"),
|
||||
request.getParameter("adrVille"),
|
||||
request.getParameter("grade"),
|
||||
request.getParameter("commentaire")
|
||||
);
|
||||
PompierMySql cm = new PompierMySql();
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package com.test.servlets;
|
||||
|
||||
import bdd.PompierMySql;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@ -57,8 +58,15 @@ public class ModifPompierServlet extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
PompierMysql PompierMs = new PompierMySql();
|
||||
request.setAttribute("unPompier", PomperMs.readAll());
|
||||
PompierMySql PompierMs = new PompierMySql();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
processRequest(request, response);
|
||||
}
|
||||
|
||||
|
@ -79,14 +79,16 @@ public class authentifServlet extends HttpServlet {
|
||||
AuthentifForm leControle = new AuthentifForm();
|
||||
// Appel de la méthode controlerRole
|
||||
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("controlForm", leControle);
|
||||
HttpSession maSession = request.getSession();
|
||||
maSession.setAttribute("isAuthentified", true);
|
||||
|
||||
// Affichage de la JSP
|
||||
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);
|
||||
}else{
|
||||
getServletContext().getRequestDispatcher("/WEB-INF/accueilJSP.jsp")
|
||||
|
@ -28,7 +28,7 @@
|
||||
<input type="email" name="eMail"/><br /><br/>
|
||||
<label for="ztLogin">Login : </label>
|
||||
<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 />
|
||||
<label for="nAdrNo">Numéro de rue : </label>
|
||||
<input type="number" name="nAdrNo"/><br /><br/>
|
||||
@ -40,8 +40,7 @@
|
||||
<input type="text" name="ztAdrVille" placeholder="Ville" /><br /><br/>
|
||||
<label for="nGrade">Numéro de grade : </label>
|
||||
<input type="number" name="nGrade"/><br /><br/>
|
||||
<input type="submit" value="="nStatut"/><br /><br/>
|
||||
<label for="eMail">Mail :Valider" />
|
||||
<input type="submit" value="Valider"/><br /><br/>resultQ.getInt("idEmployeur"),
|
||||
</form>
|
||||
</fieldset>
|
||||
|
||||
|
@ -18,42 +18,33 @@
|
||||
<legend>Fiche Pompier</legend>
|
||||
<form name="fPompier" method="POST" action="ModifPompier">
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<input type="number" name="nAdrNo"<br <c:out value="${unPompier.getAdrNo()}"/> <br/>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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" />
|
||||
</form>
|
||||
</fieldset>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -12,7 +12,7 @@
|
||||
<title>Pompier</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello World!</h1>
|
||||
<h1>Bienvenue</h1>
|
||||
<a href="ModifPompier"><input type="button" name="btModifP" value="Modifier la fiche pompier"/></a>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user