diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f53fb92 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/nbproject/private/ diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index d2c8170..e70e6ae 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -982,10 +982,19 @@ exists or setup the property manually. For example like this: + + + + - + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index f3d796d..63207e8 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=b7dbe5f7 +build.xml.data.CRC32=09107be5 build.xml.script.CRC32=14676051 build.xml.stylesheet.CRC32=1707db4f@1.98.0.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=b7dbe5f7 -nbproject/build-impl.xml.script.CRC32=ff0143c9 +nbproject/build-impl.xml.data.CRC32=09107be5 +nbproject/build-impl.xml.script.CRC32=ee796d33 nbproject/build-impl.xml.stylesheet.CRC32=334708a0@1.98.0.1 diff --git a/nbproject/project.properties b/nbproject/project.properties index 40504b3..7d07af0 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -26,15 +26,23 @@ dist.ear.war=${dist.dir}/${war.ear.name} dist.javadoc.dir=${dist.dir}/javadoc dist.war=${dist.dir}/${war.name} excludes= +file.reference.commons-lang3-3.17.0.jar=C:\\Program Files\\Apache Software Foundation\\Tomcat 10.1\\drivers\\commons-lang3-3.17.0.jar +file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar=C:\\Program Files\\Apache Software Foundation\\Tomcat 10.1\\drivers\\jakarta.servlet.jsp.jstl-2.0.0.jar +file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar=C:\\Program Files\\Apache Software Foundation\\Tomcat 10.1\\drivers\\jakarta.servlet.jsp.jstl-api-2.0.0.jar +file.reference.mysql-connector-java-8.0.23.jar=C:\\Program Files\\Apache Software Foundation\\Tomcat 10.1\\drivers\\mysql-connector-java-8.0.23.jar includes=** j2ee.compile.on.save=true j2ee.copy.static.files.on.save=true j2ee.deploy.on.save=true j2ee.platform=10-web -j2ee.platform.classpath=${j2ee.server.home}/bin/tomcat-juli.jar:${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-ssi.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.27.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jakartaee-migration-1.0.8-shaded.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jaspic-api.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote-ffm.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-cs.jar:${j2ee.server.home}/lib/tomcat-i18n-de.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-i18n-ko.jar:${j2ee.server.home}/lib/tomcat-i18n-pt-BR.jar:${j2ee.server.home}/lib/tomcat-i18n-ru.jar:${j2ee.server.home}/lib/tomcat-i18n-zh-CN.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar:${j2ee.server.home}/lib/websocket-client-api.jar +j2ee.platform.classpath=${j2ee.server.home}/bin/tomcat-juli.jar:${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-ssi.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.27.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jakartaee-migration-1.0.8-shaded.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jaspic-api.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/mysql-connector-java-8.0.23.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote-ffm.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-cs.jar:${j2ee.server.home}/lib/tomcat-i18n-de.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-i18n-ko.jar:${j2ee.server.home}/lib/tomcat-i18n-pt-BR.jar:${j2ee.server.home}/lib/tomcat-i18n-ru.jar:${j2ee.server.home}/lib/tomcat-i18n-zh-CN.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar:${j2ee.server.home}/lib/websocket-client-api.jar j2ee.server.type=Tomcat jar.compress=false -javac.classpath= +javac.classpath=\ + ${file.reference.commons-lang3-3.17.0.jar}:\ + ${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar}:\ + ${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar}:\ + ${file.reference.mysql-connector-java-8.0.23.jar} # Space-separated list of extra javac options javac.compilerargs= javac.debug=true diff --git a/nbproject/project.xml b/nbproject/project.xml index a39ecef..43dd15d 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -5,7 +5,24 @@ ap33ApplicationSDIS-V2 1.6.5 - + + + ${file.reference.commons-lang3-3.17.0.jar} + WEB-INF/lib + + + ${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar} + WEB-INF/lib + + + ${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar} + WEB-INF/lib + + + ${file.reference.mysql-connector-java-8.0.23.jar} + WEB-INF/lib + + diff --git a/src/java/bdd/CaserneMySQL.java b/src/java/bdd/CaserneMySQL.java new file mode 100644 index 0000000..09ab635 --- /dev/null +++ b/src/java/bdd/CaserneMySQL.java @@ -0,0 +1,41 @@ +/* + * bddd/CaserneMySQL.java + */ +package bdd; + +import bean.Caserne; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * + * @author Dominique_2 + */ +public class CaserneMySQL { + private final Connection laConnection = Connexion.getConnect("10.121.38.106", + "sdis29", + "adminBDsdis", + "mdpBDsdis"); + public Caserne read(int id) { + Caserne laCaserne = null; + try { + PreparedStatement prepStmt = null; + String sql = "SELECT * FROM caserne WHERE id=?"; + prepStmt = laConnection.prepareStatement(sql); + prepStmt.setInt(1, id); + ResultSet result = prepStmt.executeQuery(); + if (result.next()) { + laCaserne = new Caserne(result.getInt(1), result.getString(2), + result.getString(3), result.getString(4)); + } + prepStmt.close(); + } catch (SQLException ex) { + System.out.println("SQLExeption : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + return laCaserne; + } +} diff --git a/src/java/bdd/Connexion.java b/src/java/bdd/Connexion.java new file mode 100644 index 0000000..3c45d8c --- /dev/null +++ b/src/java/bdd/Connexion.java @@ -0,0 +1,61 @@ +package bdd; +/* +Connexion.java +Classe permettant d'établir une connexion avec une base de données mySQL +*/ +import java.sql.Connection; +import java.sql.DriverManager; + +public class Connexion { + private static Connection connect; // Variable de connexion + + /** + * Constructeur + * @param serveur nom du serveur, localhost si local + * @param bdd nom de la base de données + * @param nomUtil nom utilisateur + * @param mdp mot de passe lié à l'utilisateur + */ + private Connexion(String serveur, String bdd, String nomUtil, String mdp) { + try { + // 1. Chargement du driver + //Class.forName("com.mysql.jdbc.Driver"); + Class.forName("com.mysql.cj.jdbc.Driver"); + System.out.println("Driver accessible"); + + // 2. Initialisation des paramètres de connexion + String host = serveur; // Serveur de bd + String dbname = bdd; // Nom bd + String url = "jdbc:mysql://" + host + "/" + dbname; // url de connexion + url += "?autoReconnect=true"; // Ajout 26/09/2021 + System.out.println("url : "+url); + String user = nomUtil; // nom du user + System.out.println("nomUtil : "+nomUtil); + String passwd = mdp; // mot de passe + System.out.println("mdp : "+mdp); + + // 3. Connexion + connect = (Connection) DriverManager.getConnection(url, user, passwd); + System.out.println("Connexion réussie !"); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Retourne la connection établie (Création d'une connection si elle n'existe pas) + * @param serveur nom du serveur, localhost si local + * @param bdd nom de la base de données + * @param nomUtil nom utilisateur + * @param mdp mot de passe lié à l'utilisateur + * @return connection établie + */ + public static Connection getConnect(String serveur, String bdd, String nomUtil, String mdp) { + //System.out.println("getConnect"); + if (connect == null) { + new Connexion(serveur, bdd, nomUtil, mdp); + } + return connect; + } +} diff --git a/src/java/bdd/ParamMySQL.java b/src/java/bdd/ParamMySQL.java new file mode 100644 index 0000000..964d7a8 --- /dev/null +++ b/src/java/bdd/ParamMySQL.java @@ -0,0 +1,80 @@ +/* + * bdd/ParamMySQL.java + */ +package bdd; + + + +import bean.Parametre; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +/** + * + * @author Dominique_2 + */ +public class ParamMySQL { + + private final Connection laConnection = Connexion.getConnect("10.121.38.106", + "sdis29", + "adminBDsdis", + "mdpBDsdis"); + /** + * Recherche du paramètre correspondant au type et à l'indice passé en paramètres + * @param typeParam + * @param ind + * @return Parametre concerné ou null si non trouvé + */ + public Parametre read(String typeParam, int ind) { + Parametre leParam = null; + try { + PreparedStatement prepStmt = null; + String sql = "SELECT * FROM parametre WHERE idType=? AND indice=?"; + prepStmt = laConnection.prepareStatement(sql); + prepStmt.setString(1, typeParam); + prepStmt.setInt(2, ind); + ResultSet result = prepStmt.executeQuery(); + if (result.next()) { + leParam = new Parametre(result.getString(1), result.getInt(2), + result.getString(3)); + } + prepStmt.close(); + } catch (SQLException ex) { + System.out.println("SQLExeption : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + return leParam; + } + + /** + * Recherche de tous les paramètres du type passé en paramètre + * @param unType + * @return collection de Parametre correspondant au type + */ + public ArrayList readType(String unType) { + ArrayList lesParam = new ArrayList(); + try { + PreparedStatement prepStmt = null; + String sql = "SELECT * FROM parametre WHERE idType=? "; + prepStmt = laConnection.prepareStatement(sql); + prepStmt.setString(1, unType); + ResultSet result = prepStmt.executeQuery(); + Parametre leParam; + while (result.next()) { + leParam = new Parametre(result.getString(1), result.getInt(2), + result.getString(3)); + lesParam.add(leParam); + } + prepStmt.close(); + } catch (SQLException ex) { + System.out.println("SQLExeption : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + return lesParam; + } +} diff --git a/src/java/bdd/PompierMySQL.java b/src/java/bdd/PompierMySQL.java new file mode 100644 index 0000000..d5df64f --- /dev/null +++ b/src/java/bdd/PompierMySQL.java @@ -0,0 +1,338 @@ +/* + * bdd/PompierMysql.java + */ +package bdd; + +import bean.Caserne; +import bean.Parametre; +import bean.Pompier; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Dominique_2 + */ +public class PompierMySQL { + + private final Connection theConnection = Connexion.getConnect("10.121.38.106", + "sdis29", + "adminBDsdis", + "mdpBDsdis"); + // Tableau des attributs mis à jour + // 1ère dimension : noms des attributs en bdd + // 2ème dimension : noms des champs transmis + // 3ème dimension : type de données, i pour Integet, s pour String + private String[][] lesAttributs = { + {"id", "idCaserne", "nom", "prenom", "statut", "typePers", "mail", "login", "mdp", "adresse", "cp", "ville", "bip", "grade", "commentaire"}, + {"idP", "idC", "ztNom", "ztPrenom", "ldrStatut", "ldrType", "ztMail", "ztLogin", "ztMdp", "ztAdresse", "ztCP", "zlVille", "ztBip", "ldrGrade", "ztObs"}, + {"i", "i", "s", "s", "i", "i", "s", "s", "s", "s", "s", "s", "s", "i", "s"} + }; + + /** + * Recherche du pompier ayant le login et le mdp passé en paramètres + * + * @param login + * @param mdp + * @return Pompier correspondant ou null si non trouvé + */ + public Pompier readAuthentif(String login, String mdp) { + Pompier lePompier = null; + try { + PreparedStatement prepStmt; + String sql = "SELECT * FROM pompier WHERE login=? AND mdp=? "; + + prepStmt = theConnection.prepareStatement(sql); + prepStmt.setString(1, login); + prepStmt.setString(2, mdp); + ResultSet result = prepStmt.executeQuery(); + if (result.next()) { + CaserneMySQL laCaserneMySQL = new CaserneMySQL(); + Caserne laCaserne = laCaserneMySQL.read(result.getInt(2)); + lePompier = constituerLePompier(result, laCaserne); + } + prepStmt.close(); + } catch (SQLException ex) { + System.out.println("SQLExeption : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + return lePompier; + } + + /** + * Recherche des pompiers volontaires de la caserne + * + * @param idCaserne + * @return collection des pompiers concernés + */ + public ArrayList readLesPompiersCaserne(int idCaserne) { + ArrayList lesPompiers = new ArrayList(); + try { + PreparedStatement prepStmt; + String sql = "SELECT * FROM pompier WHERE idCaserne=? AND Statut=1 AND typePers=2 ORDER BY nom, prenom"; + + prepStmt = theConnection.prepareStatement(sql); + prepStmt.setInt(1, idCaserne); + ResultSet result = prepStmt.executeQuery(); + CaserneMySQL laCaserneMySQL = new CaserneMySQL(); + Caserne laCaserne = laCaserneMySQL.read(idCaserne); + while (result.next()) { + Pompier unPompier = constituerLePompier(result, laCaserne); + lesPompiers.add(unPompier); + } + prepStmt.close(); + } catch (SQLException ex) { + System.out.println("SQLExeption : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + return lesPompiers; + } + + public Pompier constituerLePompier(ResultSet result, Caserne laCaserne) { + Pompier lePompier = null; + ParamMySQL leParamMySQL = new ParamMySQL(); + try { + Parametre leStatut = leParamMySQL.read("statAgt", result.getInt(5)); + Parametre leType = leParamMySQL.read("typePer", result.getInt(6)); + Parametre leGrade = leParamMySQL.read("grade", result.getInt(15)); + lePompier = new Pompier(laCaserne, result.getInt(1), + result.getString(3), result.getString(4), + leStatut, leType, + result.getString(7), result.getString(8), + result.getString(9), result.getString(10), + result.getString(11), result.getString(12), + result.getString(13), leGrade, result.getString(16)); + //System.out.println("lePompier " + lePompier); + } catch (SQLException ex) { + Logger.getLogger(PompierMySQL.class.getName()).log(Level.SEVERE, null, ex); + } + return lePompier; + } + + /** + * Recherche du dernier no de pompier utilisé pour une caserne + * + * @param idC : caserne concernée + * @return dernier no de pompier utilisé dansla caserne + */ + public int getIdMax(int idC) { + int max = 0; + try { + PreparedStatement prepStmt; + String sql = "SELECT max(pId) FROM pompier WHERE pCis = ?"; + prepStmt = theConnection.prepareStatement(sql); + prepStmt.setInt(1, idC); + ResultSet result = prepStmt.executeQuery(); + if (result.first()) { + max = result.getInt(1); + } + prepStmt.close(); + } catch (SQLException ex) { + System.out.println("SQLExeption : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + return max; + } + + public Pompier update(HashMap lesParametres, int idP) { +// Date dateJ = new Date(); +// DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); +// String dateDuJour = dateFormat.format(dateJ); + Pompier lePompierMaj = null; + // Constitution de la requête en fonction des données transmises + String valeurs [] = new String[lesAttributs[1].length]; + String sql = "UPDATE pompier SET "; + int nbAttributsMaj = 0; + String virgule = ""; + for (HashMap.Entry unParam : lesParametres.entrySet()) { + // Recherche attribut correspondant au champ trnasmis + int i = 0; + while (i < lesAttributs[1].length && !(lesAttributs[1][i].equals(unParam.getKey()))) { + i++; + } + if (i < lesAttributs[0].length) { + sql += virgule + lesAttributs[0][i] + "= ?"; + valeurs[nbAttributsMaj] = "("+lesAttributs[2][i]+")" + unParam.getValue(); + nbAttributsMaj++; + virgule = ", "; + } + } + sql += ", dateModif = ? WHERE id = ?;"; + // Alimentation des valeurs de la requête + PreparedStatement prepStmt; + try { + prepStmt = theConnection.prepareStatement(sql); + for (int i=0; i 0) { + System.out.println("nbLigne " + nbLigne); + lePompierMaj = read(idP); + System.out.println("lePompierMaj : "+ lePompierMaj); + } + prepStmt.close(); + } catch (SQLException ex) { + System.out.println("SQLExeption : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + + + + + return lePompierMaj; +// String sql = "UPDATE pompier " +// + "SET pNom = ?, pPrenom = ?, pMail = ?, " +// + "pLogin = ?, pMdp = ?, pAdresse = ?, pCp = ?, pVille = ?, " +// + "pBip = ?, pGrade = ?, pCommentaire = ?, pDateModif = ? " +// + "WHERE pCis=? AND pId=?; "; +// return requeteMaj(sql, lesParametres); + } + + public Pompier create(HashMap lesParametres) { + Pompier lePompierCree = null; + // Constitution de la requête en fonction des données transmises + String valeurs [] = new String[lesAttributs[1].length]; + String sql = "INSERT INTO pompier ("; + int nbAttributsMaj = 0; + String virgule = ""; + for (HashMap.Entry unParam : lesParametres.entrySet()) { + // Recherche attribut correspondant au champ trnasmis + int i = 0; + while (i < lesAttributs[1].length && !(lesAttributs[1][i].equals(unParam.getKey()))) { + i++; + } + if (i < lesAttributs[0].length) { + sql += virgule + lesAttributs[0][i]; + valeurs[nbAttributsMaj] = "("+lesAttributs[2][i]+")" + unParam.getValue(); + nbAttributsMaj++; + virgule = ", "; + } + } + sql += ", dateEnreg) values (?"; + for (int i=0; i 0) { + ResultSet result = prepStmt.getGeneratedKeys(); + if (result.first()) { + int id = result.getInt(1); + lePompierCree = read(id); + System.out.println("lePompierCree : "+ lePompierCree); + } + } + prepStmt.close(); + } catch (SQLException ex) { + System.out.println("SQLExeption : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + + return lePompierCree; + } + + private Pompier requeteMaj(String sql, HashMap lesParametres) { + int nbLigne = 0; + try { + PreparedStatement prepStmt; + prepStmt = theConnection.prepareStatement(sql); + prepStmt.setString(1, (String) lesParametres.get("ztNom")); + prepStmt.setString(2, (String) lesParametres.get("ztPrenom")); + prepStmt.setString(3, (String) lesParametres.get("ztMail")); + prepStmt.setString(4, (String) lesParametres.get("ztLogin")); + prepStmt.setString(5, (String) lesParametres.get("ztMdp")); + prepStmt.setString(6, (String) lesParametres.get("ztAdresse")); + prepStmt.setString(7, (String) lesParametres.get("ztCP")); + prepStmt.setString(8, (String) lesParametres.get("ztVille")); + prepStmt.setString(9, (String) lesParametres.get("ztBip")); + prepStmt.setInt(10, (Integer) lesParametres.get("ldrGrade")); + prepStmt.setString(11, (String) lesParametres.get("taObs")); + //prepStmt.setDate(12, java.sql.Date.valueOf(java.time.LocalDate.now())); + prepStmt.setTimestamp(12, new Timestamp(Calendar.getInstance().getTimeInMillis())); + prepStmt.setInt(13, (Integer) lesParametres.get("idC")); + prepStmt.setInt(14, (Integer) lesParametres.get("zhIdP")); + if (sql.substring(0, 6).equals("INSERT")) { + prepStmt.setInt(15, (Integer) lesParametres.get("idStatut")); + prepStmt.setInt(16, (Integer) lesParametres.get("idType")); + } + + System.out.println(prepStmt); + nbLigne = prepStmt.executeUpdate(); + prepStmt.close(); + } catch (SQLException ex) { + System.out.println("SQLExeption : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + Pompier lePompierMaj = null; + if (nbLigne > 0) { + //lePompierMaj = read((Integer) lesParametres.get("idC"), (Integer) lesParametres.get("zhIdP")); + } + return lePompierMaj; + } + + public Pompier read(int idP) { + Pompier unPompier = null; + try { + PreparedStatement prepStmt; + String sql = "SELECT * FROM pompier WHERE id=? "; + + prepStmt = theConnection.prepareStatement(sql); + prepStmt.setInt(1, idP); + ResultSet result = prepStmt.executeQuery(); + if (result.next()) { + CaserneMySQL laCaserneMySQL = new CaserneMySQL(); + Caserne laCaserne = laCaserneMySQL.read(result.getInt(2)); + unPompier = constituerLePompier(result, laCaserne); + } + prepStmt.close(); + } catch (SQLException ex) { + System.out.println("SQLExeption : " + ex.getMessage()); + System.out.println("SQLState : " + ex.getSQLState()); + System.out.println("Code erreur : " + ex.getErrorCode()); + } + return unPompier; + } +} diff --git a/src/java/bean/Caserne.java b/src/java/bean/Caserne.java new file mode 100644 index 0000000..1f5f2b9 --- /dev/null +++ b/src/java/bean/Caserne.java @@ -0,0 +1,101 @@ +/* + * bean/Caserne.java + */ +package bean; + +import java.util.Objects; + +/** + * + * @author Dominique_2 + */ +public class Caserne { + private int id; + private String nom; + private String adresse; + private String tel; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getNom() { + return nom; + } + + public void setNom(String nom) { + this.nom = nom; + } + + public String getAdresse() { + return adresse; + } + + public void setAdresse(String adresse) { + this.adresse = adresse; + } + + public String getTel() { + return tel; + } + + public void setTel(String tel) { + this.tel = tel; + } + + + + public Caserne(int cId, String cNom, String cAdresse, String cTel) { + this.id = cId; + this.nom = cNom; + this.adresse = cAdresse; + this.tel = cTel; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 17 * hash + this.id; + hash = 17 * hash + Objects.hashCode(this.nom); + hash = 17 * hash + Objects.hashCode(this.adresse); + hash = 17 * hash + Objects.hashCode(this.tel); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Caserne other = (Caserne) obj; + if (this.id != other.id) { + return false; + } + if (!Objects.equals(this.nom, other.nom)) { + return false; + } + if (!Objects.equals(this.adresse, other.adresse)) { + return false; + } + if (!Objects.equals(this.tel, other.tel)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "Caserne{" + "id=" + id + ", nom=" + nom + ", adresse=" + adresse + ", tel=" + tel + '}'; + } + +} diff --git a/src/java/bean/Parametre.java b/src/java/bean/Parametre.java new file mode 100644 index 0000000..0fc4da4 --- /dev/null +++ b/src/java/bean/Parametre.java @@ -0,0 +1,71 @@ +/* + * bean/Parametre.java + */ +package bean; + +/** + * + * @author Dominique_2 + */ +public class Parametre { + private String typParam; + private int code; + private String valeur; + + + /** + * @return the code + */ + public int getCode() { + return code; + } + + /** + * @param code the code to set + */ + public void setCode(int code) { + this.code = code; + } + + /** + * @return the valeur + */ + public String getValeur() { + return valeur; + } + + /** + * @param valeur the valeur to set + */ + public void setValeur(String valeur) { + this.valeur = valeur; + } + + public Parametre(String typParam, int code, String valeur) { + this.typParam = typParam; + this.code = code; + this.valeur = valeur; + } + + /** + * @return the typParam + */ + public String getTypParam() { + return typParam; + } + + /** + * @param typParam the typParam to set + */ + public void setTypParam(String typParam) { + this.typParam = typParam; + } + + @Override + public String toString() { + return "Parametre{" + "typParam=" + typParam + ", code=" + code + ", valeur=" + valeur + '}'; + } + + + +} diff --git a/src/java/bean/Pompier.java b/src/java/bean/Pompier.java new file mode 100644 index 0000000..0b245ae --- /dev/null +++ b/src/java/bean/Pompier.java @@ -0,0 +1,223 @@ +/* + * bean/Pompier.java + */ +package bean; + +import java.util.Objects; + +/** + * + * @author Dominique_2 + */ +public class Pompier { + private Caserne laCaserne; + private int id; + private String nom; + private String prenom; + private Parametre leStatut; + private Parametre leType; + private String mail; + private String login; + private String mdp; + private String adresse; + private String cp; + private String ville; + private String bip; + private Parametre leGrade; + private String commentaire; + + public Caserne getLaCaserne() { + return laCaserne; + } + + public void setLaCaserne(Caserne laCaserne) { + this.laCaserne = laCaserne; + } + + public Pompier(Caserne laCaserne, int id, String nom, String prenom, Parametre leStatut, Parametre leType, String mail, String login, String mdp, String adresse, String cp, String ville, String bip, Parametre leGrade, String commentaire) { +// this.laCaserne = laCaserne; +// this.pId = pId; +// this.pNom = pNom; +// this.pPrenom = pPrenom; + this(laCaserne, id, nom, prenom); + this.leStatut = leStatut; + this.leType = leType; + this.mail = mail; + this.login = login; + this.mdp = mdp; + this.adresse = adresse; + this.cp = cp; + this.ville = ville; + this.bip = bip; + this.leGrade = leGrade; + this.commentaire = commentaire; + } + + public Pompier(Caserne laCaserne, int id, String nom, String prenom) { + this.laCaserne = laCaserne; + this.id = id; + this.nom = nom; + this.prenom = prenom; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getNom() { + return nom; + } + + public void setNom(String nom) { + this.nom = nom; + } + + public String getPrenom() { + return prenom; + } + + public void setPrenom(String prenom) { + this.prenom = prenom; + } + + public Parametre getLeStatut() { + return leStatut; + } + + public void setLeStatut(Parametre leStatut) { + this.leStatut = leStatut; + } + + public Parametre getLeType() { + return leType; + } + + public void setLeType(Parametre leType) { + this.leType = leType; + } + + public String getMail() { + return mail; + } + + public void setMail(String mail) { + this.mail = mail; + } + + public String getLogin() { + return login; + } + + public void setLogin(String login) { + this.login = login; + } + + public String getMdp() { + return mdp; + } + + public void setMdp(String mdp) { + this.mdp = mdp; + } + + public String getAdresse() { + return adresse; + } + + public void setAdresse(String adresse) { + this.adresse = adresse; + } + + public String getCp() { + return cp; + } + + public void setCp(String cp) { + this.cp = cp; + } + + public String getVille() { + return ville; + } + + public void setVille(String ville) { + this.ville = ville; + } + + public String getBip() { + return bip; + } + + public void setBip(String bip) { + this.bip = bip; + } + + public Parametre getLeGrade() { + return leGrade; + } + + public void setLeGrade(Parametre leGrade) { + this.leGrade = leGrade; + } + + public String getCommentaire() { + return commentaire; + } + + public void setCommentaire(String commentaire) { + this.commentaire = commentaire; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 67 * hash + Objects.hashCode(this.laCaserne); + hash = 67 * hash + this.id; + hash = 67 * hash + Objects.hashCode(this.nom); + hash = 67 * hash + Objects.hashCode(this.prenom); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Pompier other = (Pompier) obj; + if (this.id != other.id) { + return false; + } + + if (!Objects.equals(this.laCaserne, other.laCaserne)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "Pompier{" + "laCaserne=" + laCaserne + ", id=" + id + ", nom=" + nom + ", prenom=" + prenom + ", leStatut=" + leStatut + ", leType=" + leType + ", mail=" + mail + ", login=" + login + ", mdp=" + mdp + ", adresse=" + adresse + ", cp=" + cp + ", ville=" + ville + ", bip=" + bip + ", grade=" + leGrade + ", commentaire=" + commentaire + '}'; + } + + + + + + + + + + + + +} diff --git a/src/java/doc/readMe b/src/java/doc/readMe new file mode 100644 index 0000000..3393280 --- /dev/null +++ b/src/java/doc/readMe @@ -0,0 +1,15 @@ +Variables de session : + Variables mises en session après authentification (AuthentifForm.java) + lePompierConnecte : pompier authentifié + lePompier : pompier à afficher dans pompierJSP + lesGrades : collection des grades possibles ( + lesPeriodes : collections des périodes d'affectation possibles (nuit, matin, ...) + lesStatuts : collection des statuts (pompier, chef de centre, resp. alertes) + lesTypes : collection des types (pompier volontaires, perso médical, perso adm.) + lesPompiers : collection des pompiers de la caserne, reseignée uniquement si le pompier connecté est un chef de centre + Variables mises en session dans PompierServlet.java) + lePompier : pompier à afficher dans pompierJSP + +Attributs utilisés entre la servet PompierServlet.java et pompierJSP : + page : 2 --> affichage des données du pompier connecté + 3 --> affichage des données d'un pompier de la caserne pour le chef de centre diff --git a/src/java/filter/authentifFilter.java b/src/java/filter/authentifFilter.java new file mode 100644 index 0000000..44c7283 --- /dev/null +++ b/src/java/filter/authentifFilter.java @@ -0,0 +1,229 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Filter.java to edit this template + */ +package filter; + +import java.io.IOException; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSession; + +/** + * + * @author domin + */ +public class authentifFilter implements Filter { + + private static final boolean debug = true; + + // The filter configuration object we are associated with. If + // this value is null, this filter instance is not currently + // configured. + private FilterConfig filterConfig = null; + + public authentifFilter() { + } + + private void doBeforeProcessing(ServletRequest request, ServletResponse response) + throws IOException, ServletException { + if (debug) { + log("authentifFilter:DoBeforeProcessing"); + } + + // Write code here to process the request and/or response before + // the rest of the filter chain is invoked. + // For example, a logging filter might log items on the request object, + // such as the parameters. + /* + for (Enumeration en = request.getParameterNames(); en.hasMoreElements(); ) { + String name = (String)en.nextElement(); + String values[] = request.getParameterValues(name); + int n = values.length; + StringBuffer buf = new StringBuffer(); + buf.append(name); + buf.append("="); + for(int i=0; i < n; i++) { + buf.append(values[i]); + if (i < n-1) + buf.append(","); + } + log(buf.toString()); + } + */ + } + + private void doAfterProcessing(ServletRequest request, ServletResponse response) + throws IOException, ServletException { + if (debug) { + log("authentifFilter:DoAfterProcessing"); + } + + // Write code here to process the request and/or response after + // the rest of the filter chain is invoked. + // For example, a logging filter might log the attributes on the + // request object after the request has been processed. + /* + for (Enumeration en = request.getAttributeNames(); en.hasMoreElements(); ) { + String name = (String)en.nextElement(); + Object value = request.getAttribute(name); + log("attribute: " + name + "=" + value.toString()); + + } + */ + // For example, a filter might append something to the response. + /* + PrintWriter respOut = new PrintWriter(response.getWriter()); + respOut.println("

This has been appended by an intrusive filter."); + */ + } + + /** + * + * @param request The servlet request we are processing + * @param response The servlet response we are creating + * @param chain The filter chain we are processing + * + * @exception IOException if an input/output error occurs + * @exception ServletException if a servlet error occurs + */ + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) + throws IOException, ServletException { + + if (debug) { + log("authentifFilter:doFilter()"); + } + + // Cast de l'objet request + HttpServletRequest requete = (HttpServletRequest) request; + // Pas de filtrage des css, des images, des js + String chemin = requete.getRequestURI().substring(requete.getContextPath().length()); + //System.out.println("Chemin : " + chemin); + if (chemin.startsWith("/css") || chemin.startsWith("/images") || chemin.startsWith("/js")) { + //System.out.println(" - passage ok"); + chain.doFilter(request, response); + return; + } +// Récupération de la session + HttpSession maSession = requete.getSession(); +// Récupération du booléen d'authentification + boolean authentificationOK = false; + if (maSession.getAttribute("lePompierConnecte") != null) { + authentificationOK = true; + } + //System.out.println("authentificationOK : "+ authentificationOK); + if (authentificationOK) { + // Poursuite sans problème + chain.doFilter(request, response); + } else { + // retour vers la page d'authentification + request.getRequestDispatcher("authentification").forward(request, response); + } + } + + /** + * Return the filter configuration object for this filter. + */ + public FilterConfig getFilterConfig() { + return (this.filterConfig); + } + + /** + * Set the filter configuration object for this filter. + * + * @param filterConfig The filter configuration object + */ + public void setFilterConfig(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } + + /** + * Destroy method for this filter + */ + public void destroy() { + } + + /** + * Init method for this filter + */ + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + if (filterConfig != null) { + if (debug) { + log("authentifFilter:Initializing filter"); + } + } + } + + /** + * Return a String representation of this object. + */ + @Override + public String toString() { + if (filterConfig == null) { + return ("authentifFilter()"); + } + StringBuffer sb = new StringBuffer("authentifFilter("); + sb.append(filterConfig); + sb.append(")"); + return (sb.toString()); + } + + private void sendProcessingError(Throwable t, ServletResponse response) { + String stackTrace = getStackTrace(t); + + if (stackTrace != null && !stackTrace.equals("")) { + try { + response.setContentType("text/html"); + PrintStream ps = new PrintStream(response.getOutputStream()); + PrintWriter pw = new PrintWriter(ps); + pw.print("\n\nError\n\n\n"); //NOI18N + + // PENDING! Localize this for next official release + pw.print("

The resource did not process correctly

\n
\n");                
+                pw.print(stackTrace);                
+                pw.print("
\n"); //NOI18N + pw.close(); + ps.close(); + response.getOutputStream().close(); + } catch (Exception ex) { + } + } else { + try { + PrintStream ps = new PrintStream(response.getOutputStream()); + t.printStackTrace(ps); + ps.close(); + response.getOutputStream().close(); + } catch (Exception ex) { + } + } + } + + public static String getStackTrace(Throwable t) { + String stackTrace = null; + try { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + t.printStackTrace(pw); + pw.close(); + sw.close(); + stackTrace = sw.getBuffer().toString(); + } catch (Exception ex) { + } + return stackTrace; + } + + public void log(String msg) { + filterConfig.getServletContext().log(msg); + } + +} diff --git a/src/java/form/AuthentifForm.java b/src/java/form/AuthentifForm.java new file mode 100644 index 0000000..3ca6f81 --- /dev/null +++ b/src/java/form/AuthentifForm.java @@ -0,0 +1,75 @@ +/* + * form/authentifForm.java + * Controle des données saisie dans le formulaire d'authentification + */ +package form; + +import bdd.ParamMySQL; +import bdd.PompierMySQL; +import bean.Parametre; +import bean.Pompier; +import com.sun.net.httpserver.HttpServer; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSession; +import java.util.ArrayList; +import util.CtrlSaisie; +import util.MD5; + +/** + * + * @author domin + */ +public class AuthentifForm { + String message; + HttpServletRequest request; + + public AuthentifForm(HttpServletRequest request) { + this.request = request; + } + + public boolean ctrlAuthentif() { + request.removeAttribute("message"); + // Vérification de la présence des zones obligatoires + String[] champsObligatoires = {"ztLogin", "ztMDP"}; + if (!CtrlSaisie.CtrlChampsObligatoires(request, champsObligatoires)) { + return false; + } + + // Vérification absence de chevron + if (!CtrlSaisie.CtrlChevron(request)) { + return false; + } + return true; + } + + public boolean ctrlBDD() { + boolean trouve = false; + String login = request.getParameter("ztLogin"); + String mdp = MD5.encode(request.getParameter("ztMDP")); + PompierMySQL pompierMySQL = new PompierMySQL(); + Pompier lePompier = pompierMySQL.readAuthentif(login, mdp); + if (lePompier!= null) { + trouve = true; + HttpSession maSession = request.getSession(); + maSession.setAttribute("lePompierConnecte", lePompier); + ParamMySQL paramMySQL = new ParamMySQL(); + ArrayList lesGrades = paramMySQL.readType("grade"); + maSession.setAttribute("lesGrades", lesGrades); + ArrayList lesPeriodes = paramMySQL.readType("tranche"); + maSession.setAttribute("lesPeriodes", lesPeriodes); + ArrayList lesStatuts = paramMySQL.readType("statAgt"); + maSession.setAttribute("lesStatuts", lesStatuts); + ArrayList lesTypes = paramMySQL.readType("typePer"); + maSession.setAttribute("lesTypes", lesTypes); + if (lePompier.getLeStatut().getCode()==2) { + // Recherche des pompiers de la caserne + ArrayList lesPompiers = pompierMySQL.readLesPompiersCaserne(lePompier.getLaCaserne().getId()); + maSession.setAttribute("lesPompiers", lesPompiers); + } + } else { + request.setAttribute("message", "Login ou mot de passe erroné"); + } + + return trouve; + } +} diff --git a/src/java/servlets/AuthentifServlet.java b/src/java/servlets/AuthentifServlet.java new file mode 100644 index 0000000..96f463c --- /dev/null +++ b/src/java/servlets/AuthentifServlet.java @@ -0,0 +1,118 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template + */ +package servlets; + +import bean.Pompier; +import form.AuthentifForm; +import java.io.IOException; +import java.io.PrintWriter; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import java.util.ArrayList; + +/** + * + * @author sio + */ +@WebServlet(name = "AuthentifServlet", urlPatterns = {"/"}) +public class AuthentifServlet extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + /* TODO output your page here. You may use following sample code. */ + out.println(""); + out.println(""); + out.println(""); + out.println("Servlet AuthentifServlet"); + out.println(""); + out.println(""); + out.println("

Servlet AuthentifServlet at " + request.getContextPath() + "

"); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + //processRequest(request, response); + // Suppression des variables de session + System.out.println("doGet AuthentifServlet"); + HttpSession maSession = request.getSession(); + maSession.removeAttribute("lePompierConnecte"); + maSession.removeAttribute("lesPompiers"); + maSession.removeAttribute("lePompier"); + getServletContext().getRequestDispatcher("/WEB-INF/authentifJSP.jsp").forward(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + //processRequest(request, response); + Pompier lePompier = null; + int page = 2; + AuthentifForm af = new AuthentifForm(request); + if (af.ctrlAuthentif() && af.ctrlBDD()) { // Contrôle des zones saisies et contrôle en base de données + HttpSession maSession = request.getSession(); + lePompier = (Pompier) maSession.getAttribute("lePompierConnecte"); + if (lePompier.getLeStatut().getCode()==2) { // Chef de centre + ArrayList lesPompiers = (ArrayList ) maSession.getAttribute("lesPompiers"); + if (lesPompiers.size() > 0) { + lePompier = lesPompiers.get(0); + page = 3; + } + } + request.setAttribute("page", page); + //request.setAttribute("lePompier", lePompier); + maSession.setAttribute("lePompier", lePompier); + getServletContext().getRequestDispatcher("/WEB-INF/pompierJSP.jsp").forward(request, response); + } else { // Une erreur a été détectée + getServletContext().getRequestDispatcher("/WEB-INF/authentifJSP.jsp").forward(request, response); + } + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/src/java/util/CtrlSaisie.java b/src/java/util/CtrlSaisie.java new file mode 100644 index 0000000..5954849 --- /dev/null +++ b/src/java/util/CtrlSaisie.java @@ -0,0 +1,64 @@ +/* + * util/CtrlSaisie.java + */ +package util; + +import jakarta.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.Enumeration; + +/** + * + * @author domin + */ +public abstract class CtrlSaisie { + /** + * Vérifie la présence des champs obligatoires dans les paramètres transmis + * @param request + * @param champsObligatoires : tableau de chaine de caractères, avec le nom des champs obligatoires + * @return booléen + */ + public static boolean CtrlChampsObligatoires(HttpServletRequest request, String[] champsObligatoires) { + ArrayList champsPresents = new ArrayList<>(request.getParameterMap().keySet()); + int i = 0; + int nbChampsO = champsObligatoires.length; + boolean erreur = false; + while (erreur == false && i < nbChampsO && champsPresents.contains(champsObligatoires[i])){ + String value=request.getParameter(champsObligatoires[i]); + if (value.trim().length() > 0) { + i++; + } else { + erreur = true; + } + } + if (i < nbChampsO) { + request.setAttribute("message", "Veuillez renseigner toutes les zones obligatoires ("+i+')'); + } + return (i>=nbChampsO); + } + + /** + * Contrôle si un champ de saisie contient un chevron + * @param request + * @return 0 sinon, -1 si oui + */ + public static boolean CtrlChevron(HttpServletRequest request) { + // Contrôle car "<" dans les zones de texte + Enumeration lesNoms = request.getParameterNames(); + int erreur = 0; + //ArrayList parameterNames = new ArrayList(request.getParameterMap().keySet()); + while (erreur == 0 && lesNoms.hasMoreElements()) { + Object paramObjet=lesNoms.nextElement(); + String param=(String) paramObjet; + String value=request.getParameter(param); + if (value.contains("<") || value.contains("<")) { + String message = "Veuillez recommencer votre saisie, une anomalie sur une zone de saisie a été détectée "; + request.setAttribute("message", message); + erreur=1; + } + } + return (erreur > 0) ? false : true; + + } + +} diff --git a/src/java/util/MD5.java b/src/java/util/MD5.java new file mode 100644 index 0000000..cccd368 --- /dev/null +++ b/src/java/util/MD5.java @@ -0,0 +1,36 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package util; + +/** + * + * @author sio + */ + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.logging.Level; +import java.util.logging.Logger; + +public abstract class MD5 { + + public static String encode(String uneChaine){ + MessageDigest md = null; + try { + md = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException ex) { + throw new IllegalArgumentException(ex); + } + md.update(uneChaine.getBytes()); + byte[] digest = md.digest(); + //myHash = DatatypeConverter.printHexBinary(digest).toLowerCase(); + StringBuilder sb = new StringBuilder(); + for (byte b : digest) { + sb.append(String.format("%02x", b)); + } + return sb.toString(); + } +} diff --git a/web/WEB-INF/authentifJSP.jsp b/web/WEB-INF/authentifJSP.jsp new file mode 100644 index 0000000..e2e951e --- /dev/null +++ b/web/WEB-INF/authentifJSP.jsp @@ -0,0 +1,41 @@ +<%-- + Document : authentifJSP + Created on : 23 oct. 2021, 10:02:18 + Author : domin +--%> +<%@include file= "jspf/debutJSP.jspf" %> + + + <%@include file= "jspf/header.jspf" %> +
+ +
+
+ + Authentification + +
+
+ + +
+
+ + +
+
+ +
+
+ ${message} +
+
+ <%@include file= "jspf/footer.jspf" %> +
+ + + + + diff --git a/web/WEB-INF/jspf/debutJSP.jspf b/web/WEB-INF/jspf/debutJSP.jspf new file mode 100644 index 0000000..1331b5f --- /dev/null +++ b/web/WEB-INF/jspf/debutJSP.jspf @@ -0,0 +1,16 @@ +<%-- jspf/debutJSP.jsp --%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + + + + + + + + + SDIS29 + diff --git a/web/WEB-INF/jspf/footer.jspf b/web/WEB-INF/jspf/footer.jspf new file mode 100644 index 0000000..4362381 --- /dev/null +++ b/web/WEB-INF/jspf/footer.jspf @@ -0,0 +1,5 @@ +<%-- jspf/footer.jspf --%> +<%@ page pageEncoding="UTF-8" %> +
+

SDIS 29 - 58, avenue de Keradennec - 29337 QUIMPER CEDEX - 02 98 10 31 50

+
diff --git a/web/WEB-INF/jspf/formChoixPompier.jspf b/web/WEB-INF/jspf/formChoixPompier.jspf new file mode 100644 index 0000000..18e8629 --- /dev/null +++ b/web/WEB-INF/jspf/formChoixPompier.jspf @@ -0,0 +1,21 @@ +<%-- any content can be specified here e.g.: --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ page pageEncoding="UTF-8" %> + +
+
+
+ + ici se trouvera la liste déroulante des pompiers +
+
+ + + +
+
+
+ + + + diff --git a/web/WEB-INF/jspf/formulairePompier.jspf b/web/WEB-INF/jspf/formulairePompier.jspf new file mode 100644 index 0000000..febff0e --- /dev/null +++ b/web/WEB-INF/jspf/formulairePompier.jspf @@ -0,0 +1,4 @@ +<%@ page pageEncoding="UTF-8" %> +Ici se trouvera le formulaire permettant de gérer les informations sur un pompier pour les afficher, les modifier ou les créer + + diff --git a/web/WEB-INF/jspf/header.jspf b/web/WEB-INF/jspf/header.jspf new file mode 100644 index 0000000..2cdb0e7 --- /dev/null +++ b/web/WEB-INF/jspf/header.jspf @@ -0,0 +1,45 @@ +<%-- jspf/header.jspf --%> +<%@ page pageEncoding="UTF-8" %> + +
+
+ + +
+
+ + +

Bienvenue

+
+ +

Bienvenue XXXXX +

+ + +
+
+
+

Service Départemental d'Incendie et de Secours du Finistère

+ + Afficher ici les coordonnées de la caserne du pompier connecté + + +
+
+
\ No newline at end of file diff --git a/web/WEB-INF/pompierJSP.jsp b/web/WEB-INF/pompierJSP.jsp new file mode 100644 index 0000000..5066db6 --- /dev/null +++ b/web/WEB-INF/pompierJSP.jsp @@ -0,0 +1,50 @@ +<%-- + pompierJSP.jsp +--%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@include file= "jspf/debutJSP.jspf" %> + + + <%@include file= "jspf/header.jspf" %> +
+
+ + + + + Données du pompier + + + + Données du pompier à créer + + +
+ <%@include file= "jspf/formChoixPompier.jspf" %> +
+
+
+ +
+ + ${legend} + + + <%@include file= "jspf/formulairePompier.jspf" %> +
+
+ + <%@include file= "jspf/footer.jspf" %> +
+ + + + + + + + + + + + diff --git a/web/css/mycss.css b/web/css/mycss.css new file mode 100644 index 0000000..7f41c78 --- /dev/null +++ b/web/css/mycss.css @@ -0,0 +1,86 @@ +/* + css/mycss.css +*/ + +body { + background-color: #ECECEC; +} +#contenuAffiche { + display: flex; + justify-content:center; + padding-top: 10px; + padding-bottom: 10px; + background-color: #ffffff; + border-radius: 5px; + } +#authentif { + width : 50%; +} +fieldset { + border-radius: 5px; + padding: 5px; + border: 1px solid #DB0005; + width: 100%; +} +legend { + margin-bottom:0px; + padding-bottom: 0px; +} +footer { + margin-top: 10px; + background-color: #EDEDED; + text-align: center; + font-size: smaller; + padding: 10px; + /*border-bottom: 3px solid #DB0005; */ +} +header { + background-color: #333333; + color: #EDEDED; + padding: 10px; + +} +#entete { + display: flex; + /* align-items: center; */ + align-items: flex-end ; +} + +li { + text-align: center; +} +li:not(:first-child) { + border-left: 2px solid #EDEDED; +} +#identite { + width : 100%; +} +.navbar { + padding: 0 0 0 0; + border-radius: 5px; + margin-left: -8%; +} +#logo { + z-index:1; /* arriere plan */ +} +#login { + background-color: #EDEDED; + color: #333333; + display: flex; + justify-content:space-around; + align-items: center; + margin-left: -8%; +} + +button a { + text-decoration:none; + color: #333333; +} +aside, #btAfficherPompier { + justify-content: center; + display: flex; + align-items: center; +} +select[readonly] { + pointer-events: none; +} diff --git a/web/images/favicon.ico b/web/images/favicon.ico new file mode 100644 index 0000000..68f069d Binary files /dev/null and b/web/images/favicon.ico differ diff --git a/web/images/logo-sdis.png b/web/images/logo-sdis.png new file mode 100644 index 0000000..c15050e Binary files /dev/null and b/web/images/logo-sdis.png differ diff --git a/web/images/pompier.png b/web/images/pompier.png new file mode 100644 index 0000000..fbff3ae Binary files /dev/null and b/web/images/pompier.png differ diff --git a/web/js/ctrlCodePostal.js b/web/js/ctrlCodePostal.js new file mode 100644 index 0000000..8bf094b --- /dev/null +++ b/web/js/ctrlCodePostal.js @@ -0,0 +1,28 @@ + // Recherche de la ou des villes correspondantes au code postal saisi (exemple 54490 --> 7 villes) + ztCP.onchange = function () { + //alert("ztCP a changé"); + msgCP.textContent = ""; + zlVille.length = 0; + const XHTTP = new XMLHttpRequest(); + XHTTP.onload = function () { + if (this.status != 200) { + msgCP.textContent = "Code postal erroné"; + } else { + var lesVilles = JSON.parse(this.responseText); + var info = ""; + if (lesVilles.length > 1) { + info += ""; + } + for (var i = 0; i < lesVilles.length; i++) { + var uneVille = lesVilles[i]; + info += "'; + } + zlVille.innerHTML = info; + } + } + var cp = ztCP.value; + XHTTP.open("GET", "https://apicarto.ign.fr/api/codes-postaux/communes/" + cp); + XHTTP.send(); + } +