Merge origin/master

Conflicts:
	web/WEB-INF/AuthentificationJSP.jsp
This commit is contained in:
thomas.millot 2021-10-21 14:13:15 +02:00
parent 1a26976d0a
commit 0ec37013ed
3 changed files with 136 additions and 10 deletions

View File

@ -32,6 +32,135 @@ public class PompierMysql {
theConnection = Connexion.getConnect("localhost", "sdis29", "admin", "minda");
}
public ArrayList<Pompier> readAll() {
ArrayList<Pompier> lesPompiers = new ArrayList<>();
try {
Statement stmt = theConnection.createStatement();
ResultSet resultQ = null;
resultQ = stmt.executeQuery("SELECT * FROM pompier");
while (resultQ.next()) {
unPompier = new Pompier(resultQ.getInt("id"),
resultQ.getString("nom"),
resultQ.getString("prenom"),
resultQ.getString("statut"),
resultQ.getString("typePers"),
resultQ.getString("mail"),
resultQ.getString("login"),
resultQ.getString("mdp"),
resultQ.getString("adresse"),
resultQ.getInt("cp"),
resultQ.getString("ville"),
resultQ.getInt("bip"),
resultQ.getInt("nbGardes"),
resultQ.getInt("grade"),
resultQ.getString("commentaire"),
resultQ.getString("dateEnreg"),
resultQ.getString("dateModif"));
lesPompiers.add(unPompier);
}
resultQ.close();
stmt.close();
//theConnection.close();
} catch (SQLException ex) {
System.out.println("SQLException : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return lesPompiers;
}
/**
* Creation du client passé en paramètre dans la table client Requête non
* préparée
*
* @param c objet de type Client (sans identifiant)
* @return int : id du client créé
*/
public int create(Pompier p) {
int id = -1;
try {
Statement stmt = theConnection.createStatement();
int status = stmt.executeUpdate(
"INSERT INTO pompier (nom, prenom, statut, mail, login, mdp, adresse, cp, ville, bip, nbGardes, grade, commentaire, dateEnreg, dateModif) "
+ "VALUES ('" + p.getNom() + "', '"
+ p.getPrenom() + "', '"
+ p.getStatut() + "', "
+ p.getMail() + ", '"
+ p.getLogin() + "', '"
+ p.getMdp() + "', '"
+ p.getAdresse() + "', '"
+ p.getVille() + "', '"
+ p.getBip() + "', '"
+ p.getNbGardes() + "', '"
+ p.getGrade() + "', '"
+ p.getCommentaire() + "', '"
+ p.getDateEnreg() + "', '"
+ p.getDateModif() + "');",
Statement.RETURN_GENERATED_KEYS);
// Recherche de l'identifiant du client 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 client passé en paramètre dans la table client Requête
* préparée
*
* @param c objet de type Client (sans identifiant)
* @return int : id du client créé
*/
public int createRP(Pompier p) {
int id = -1;
try {
PreparedStatement stmt = null;
String sql = "INSERT INTO pompier (nom, prenom, statut, mail, login, mdp, adresse, cp, ville, bip, nbGardes, grade, commentaire, dateEnreg, dateModif) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
stmt = theConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, p.getNom());
stmt.setString(2, p.getPrenom());
stmt.setString(3, p.getStatut());
stmt.setString(4, p.getMail());
stmt.setString(5, p.getLogin());
stmt.setString(6, p.getMdp());
stmt.setString(7, p.getAdresse());
stmt.setString(8, p.getVille());
stmt.setInt(9, p.getBip());
stmt.setInt(10, p.getNbGardes());
stmt.setInt(11, p.getGrade());
stmt.setString(12, p.getCommentaire());
stmt.setString(13, p.getDateEnreg());
stmt.setString(14, p.getDateModif());
System.out.println("Requête : " + stmt.toString());
int status = stmt.executeUpdate();
// Recherche de l'identifiant du client 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;
}
public boolean readPompier(HttpServletRequest request) {
boolean reponse = false;
Statement stmt;
@ -51,6 +180,7 @@ public class PompierMysql {
}
return reponse;
}
}

View File

@ -28,7 +28,10 @@ public class AuthentifForm {
public boolean authentifPompier(HttpServletRequest request)
{
PompierMysql pms = new PompierMysql();
return pms.readPompier(request);
boolean reponse = pms.readPompier(request);
resultat = reponse ?"": "login ou mot de passe incorrect";
request.setAttribute("message", resultat);
return reponse;
}
}

View File

@ -9,10 +9,8 @@
<!-- Affichage du formulaire si l'utilisateur ne s'est pas encore authentifié -->
<div id="contenu">
<h2>Merci de vous identifier pour acceder aux dossiers</h2>
<form name="frmIdentification" method="POST" action="Authentif">
<c:choose>
<c:when test="${empty param.ztPseudo}">
<h2>Merci de vous identifier pour acceder aux dossiers</h2>
<fieldset><legend>Identification utilisateur</legend>
<br /><br />
<label for="nom">Nom du compte</label>
@ -25,13 +23,8 @@
<input type="submit" name="valider" value="Valider">
<input type="reset" name="annuler" value="Annuler">
</p>
<p>${message}</p>
</fieldset>
</c:when>
<c:otherwise>
<p>${controlForm.getResultat()}</p>
</c:otherwise>
</c:choose>
</form>
<br /><br/>
</div>