From 8b2130a5cfe96abfa59e51d15c22c7c2c8332b23 Mon Sep 17 00:00:00 2001 From: "clementine.desrucques" Date: Tue, 19 Oct 2021 08:55:06 +0200 Subject: [PATCH] --- .gitignore | 3 + build.xml | 71 + nbproject/ant-deploy.xml | 57 + nbproject/build-impl.xml | 1434 +++++++++++++++++ nbproject/genfiles.properties | 17 + nbproject/project.properties | 104 ++ nbproject/project.xml | 34 + src/conf/MANIFEST.MF | 2 + src/java/bdd/Connexion.java | 68 + src/java/bdd/PompierMySql.java | 122 ++ src/java/com/test/beans/Pompier.java | 233 +++ src/java/com/test/beans/User.java | 68 + src/java/com/test/forms/AuthentifForm.java | 55 + src/java/com/test/forms/NouveauPompForm.java | 76 + .../com/test/servlets/ChefCaserneServlet.java | 86 + .../com/test/servlets/PompierServlet.java | 86 + .../com/test/servlets/authentifServlet.java | 109 ++ web/META-INF/context.xml | 2 + web/WEB-INF/ChefCaserneJSP.jsp | 17 + web/WEB-INF/CreaPompier.jsp | 47 + web/WEB-INF/ModifPompier.jsp | 17 + web/WEB-INF/PompierJSP.jsp | 17 + web/WEB-INF/accueilJSP.jsp | 33 + web/WEB-INF/web.xml | 32 + web/index.html | 16 + 25 files changed, 2806 insertions(+) create mode 100644 .gitignore create mode 100644 build.xml create mode 100644 nbproject/ant-deploy.xml create mode 100644 nbproject/build-impl.xml create mode 100644 nbproject/genfiles.properties create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/conf/MANIFEST.MF create mode 100644 src/java/bdd/Connexion.java create mode 100644 src/java/bdd/PompierMySql.java create mode 100644 src/java/com/test/beans/Pompier.java create mode 100644 src/java/com/test/beans/User.java create mode 100644 src/java/com/test/forms/AuthentifForm.java create mode 100644 src/java/com/test/forms/NouveauPompForm.java create mode 100644 src/java/com/test/servlets/ChefCaserneServlet.java create mode 100644 src/java/com/test/servlets/PompierServlet.java create mode 100644 src/java/com/test/servlets/authentifServlet.java create mode 100644 web/META-INF/context.xml create mode 100644 web/WEB-INF/ChefCaserneJSP.jsp create mode 100644 web/WEB-INF/CreaPompier.jsp create mode 100644 web/WEB-INF/ModifPompier.jsp create mode 100644 web/WEB-INF/PompierJSP.jsp create mode 100644 web/WEB-INF/accueilJSP.jsp create mode 100644 web/WEB-INF/web.xml create mode 100644 web/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5f4b063 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/build/ +/dist/ +/nbproject/private/ diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..307672e --- /dev/null +++ b/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + Builds, tests, and runs the project ProjetSDIS29_3. + + + diff --git a/nbproject/ant-deploy.xml b/nbproject/ant-deploy.xml new file mode 100644 index 0000000..c2349eb --- /dev/null +++ b/nbproject/ant-deploy.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..9a02988 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1434 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set build.web.dir + Must set build.generated.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.war + + + + + + + + + +The Java EE server classpath is not correctly set up - server home directory is missing. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Dj2ee.server.home=<app_server_installation_directory> + + +The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) +or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +The libs.CopyLibs.classpath property is not set up. +This property must point to +org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part +of NetBeans IDE installation and is usually located at +<netbeans_installation>/java<version>/ant/extra folder. +Either open the project in the IDE and make sure CopyLibs library +exists or setup the property manually. For example like this: + ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must select a file in the IDE or set jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. + + + Launching ${browse.url} + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..00ac89d --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,17 @@ +<<<<<<< HEAD +build.xml.data.CRC32=a917c93e +======= +build.xml.data.CRC32=6d18b965 +>>>>>>> origin/master +build.xml.script.CRC32=9531f85e +build.xml.stylesheet.CRC32=1707db4f@1.86.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. +<<<<<<< HEAD +nbproject/build-impl.xml.data.CRC32=a917c93e +nbproject/build-impl.xml.script.CRC32=33be3f4b +======= +nbproject/build-impl.xml.data.CRC32=6d18b965 +nbproject/build-impl.xml.script.CRC32=6afad90d +>>>>>>> origin/master +nbproject/build-impl.xml.stylesheet.CRC32=334708a0@1.86.0.1 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..b7a6435 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,104 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.web.dir}/WEB-INF/classes +build.classes.excludes=**/*.java,**/*.form +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +build.web.dir=${build.dir}/web +build.web.excludes=${build.classes.excludes} +client.urlPart= +compile.jsps=false +conf.dir=${source.root}/conf +debug.classpath=${build.classes.dir}:${javac.classpath} +debug.test.classpath=\ + ${run.test.classpath} +display.browser=true +# Files to be excluded from distribution war +dist.archive.excludes= +dist.dir=dist +dist.ear.war=${dist.dir}/${war.ear.name} +dist.javadoc.dir=${dist.dir}/javadoc +dist.war=${dist.dir}/${war.name} +endorsed.classpath=\ + ${libs.javaee-endorsed-api-7.0.classpath} +excludes= +<<<<<<< HEAD +file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar=/home/clementine.desrucques/T\u00e9l\u00e9chargements/jakarta.servlet.jsp.jstl-2.0.0.jar +file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar-1=../../T\u00e9l\u00e9chargements/jakarta.servlet.jsp.jstl-2.0.0.jar +file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar=/home/clementine.desrucques/T\u00e9l\u00e9chargements/jakarta.servlet.jsp.jstl-api-2.0.0.jar +======= +file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar=../../../funcha.ahamadi/T\u00e9l\u00e9chargements/jakarta.servlet.jsp.jstl-2.0.0.jar +file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar=../../../funcha.ahamadi/T\u00e9l\u00e9chargements/jakarta.servlet.jsp.jstl-api-2.0.0.jar +file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar-1=../../T\u00e9l\u00e9chargements/jakarta.servlet.jsp.jstl-api-2.0.0.jar +file.reference.mysql-connector-java-8.0.26.jar=../../../../usr/share/java/mysql-connector-java-8.0.26.jar +>>>>>>> origin/master +includes=** +j2ee.compile.on.save=true +j2ee.copy.static.files.on.save=true +j2ee.deploy.on.save=true +j2ee.platform=1.7-web +j2ee.platform.classpath=${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.20.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jakartaee-migration-1.0.0-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.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.type=Tomcat +jar.compress=false +javac.classpath=\ + <<<<<<< HEAD:\ + ${file.reference.mysql-connector-java-8.0.26.jar}:\ + ${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar-1}:\ + ${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar-1} + ${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar}:\ + ${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar} +======= + ${file.reference.mysql-connector-java-8.0.26.jar}:\ + ${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar}:\ + ${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar} +>>>>>>> origin/master +# Space-separated list of extra javac options +javac.compilerargs= +javac.debug=true +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.preview=true +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +lib.dir=${web.docbase.dir}/WEB-INF/lib +persistence.xml.dir=${conf.dir} +platform.active=default_platform +resource.dir=setup +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +# Space-separated list of JVM arguments used when running a class with a main method or a unit test +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): +runmain.jvmargs= +source.encoding=UTF-8 +source.root=src +src.dir=${source.root}/java +test.src.dir=test +war.content.additional= +war.ear.name=${war.name} +war.name=ProjetSDIS29_3.war +web.docbase.dir=web +webinf.dir=web/WEB-INF diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..892fbf9 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,34 @@ + + + org.netbeans.modules.web.project + + + ProjetSDIS29_3 + 1.6.5 + + + ${<<<<<<< HEAD} + + + ${file.reference.mysql-connector-java-8.0.26.jar} + WEB-INF/lib + + + ${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar-1} + WEB-INF/lib + + + ${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar-1} + WEB-INF/lib + + + + + + + + + + + + diff --git a/src/conf/MANIFEST.MF b/src/conf/MANIFEST.MF new file mode 100644 index 0000000..59499bc --- /dev/null +++ b/src/conf/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/src/java/bdd/Connexion.java b/src/java/bdd/Connexion.java new file mode 100644 index 0000000..4a7f4d6 --- /dev/null +++ b/src/java/bdd/Connexion.java @@ -0,0 +1,68 @@ +/* + * 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 bdd; + +import java.sql.Connection; +import java.sql.DriverManager; + +/** + * + * @author clementine.desrucques + */ + +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/PompierMySql.java b/src/java/bdd/PompierMySql.java new file mode 100644 index 0000000..e0f5a59 --- /dev/null +++ b/src/java/bdd/PompierMySql.java @@ -0,0 +1,122 @@ +/* + * 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 bdd; + +import com.test.beans.Pompier; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; + +/** + * + * @author clementine.desrucques + */ +public class PompierMySql { + + private Connection theConnection; + private Pompier unPompier; + + /** + * Constructeur + */ + public PompierMySql() { + theConnection = Connexion.getConnect("localhost", //s erveur + "sdis29", // base de données + "admin",// user + "minda"); // mot de passe ClientMysql() { + } + + /** + * 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 (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 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(idCaserne, nom, prenom, statut, mail, login, mdp, adrNo, adrRue, adrCP, adrVille, grade) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?);"; + stmt = theConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); + stmt.setInt(1, p.getIdCaserne()); + stmt.setString(2, p.getNom()); + stmt.setString(3, p.getPrenom()); + stmt.setInt(4, p.getStatut()); + stmt.setString(5,p.getMail() ); + stmt.setString(6,p.getLogin() ); + stmt.setString(7,p.getMdp() ); + stmt.setInt(8, p.getAdrNo()); + stmt.setString(9, p.getAdrRue()); + stmt.setString(10, p.getAdrCP()); + stmt.setString(11, p.getAdrVille()); + stmt.setInt(12, p.getGrade()); + + 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; + } + + +} \ No newline at end of file diff --git a/src/java/com/test/beans/Pompier.java b/src/java/com/test/beans/Pompier.java new file mode 100644 index 0000000..6771412 --- /dev/null +++ b/src/java/com/test/beans/Pompier.java @@ -0,0 +1,233 @@ +/* + * 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 com.test.beans; + +import java.util.Objects; + +/** + * + * @author clementine.desrucques + */ +public class Pompier { + private int id; + private int idCaserne; + private String nom; + private String prenom; + private int statut; + private String mail; + private String login; + private String mdp; + private int adrNo; + private String adrRue; + private String adrCP; + private String adrVille; + private int grade; + + public Pompier(int id, int idCaserne, String nom, String prenom, int statut, String mail, String login, String mdp, int adrNo, String adrRue, String adrCP, String adrVille, int grade) { + this(idCaserne, nom, prenom, statut, mail, login, mdp, adrNo, adrRue, adrCP, adrVille, grade); + this.id = id; + } + + public Pompier(int idCaserne, String nom, String prenom, int statut, String mail, String login, String mdp, int adrNo, String adrRue, String adrCP, String adrVille, int grade) { + this.idCaserne = idCaserne; + this.nom = nom; + this.prenom = prenom; + this.statut = statut; + this.mail = mail; + this.login = login; + this.mdp = mdp; + this.adrNo = adrNo; + this.adrRue = adrRue; + this.adrCP = adrCP; + this.adrVille = adrVille; + this.grade = grade; + } + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getIdCaserne() { + return idCaserne; + } + + public void setIdCaserne(int idCaserne) { + this.idCaserne = idCaserne; + } + + 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 int getStatut() { + return statut; + } + + public void setStatut(int statut) { + this.statut = statut; + } + + 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 int getAdrNo() { + return adrNo; + } + + public void setAdrNo(int adrNo) { + this.adrNo = adrNo; + } + + public String getAdrRue() { + return adrRue; + } + + public void setAdrRue(String adrRue) { + this.adrRue = adrRue; + } + + public String getAdrCP() { + return adrCP; + } + + public void setAdrCP(String adrCP) { + this.adrCP = adrCP; + } + + public String getAdrVille() { + return adrVille; + } + + public void setAdrVille(String adrVille) { + this.adrVille = adrVille; + } + + public int getGrade() { + return grade; + } + + public void setGrade(int grade) { + this.grade = grade; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 29 * hash + this.id; + hash = 29 * hash + this.idCaserne; + hash = 29 * hash + Objects.hashCode(this.nom); + hash = 29 * hash + Objects.hashCode(this.prenom); + hash = 29 * hash + this.statut; + hash = 29 * hash + Objects.hashCode(this.mail); + hash = 29 * hash + Objects.hashCode(this.login); + hash = 29 * hash + Objects.hashCode(this.mdp); + hash = 29 * hash + this.adrNo; + hash = 29 * hash + Objects.hashCode(this.adrRue); + hash = 29 * hash + Objects.hashCode(this.adrCP); + hash = 29 * hash + Objects.hashCode(this.adrVille); + hash = 29 * hash + this.grade; + 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 (this.idCaserne != other.idCaserne) { + return false; + } + if (this.statut != other.statut) { + return false; + } + if (this.adrNo != other.adrNo) { + return false; + } + if (this.grade != other.grade) { + return false; + } + if (!Objects.equals(this.nom, other.nom)) { + return false; + } + if (!Objects.equals(this.prenom, other.prenom)) { + return false; + } + if (!Objects.equals(this.mail, other.mail)) { + return false; + } + if (!Objects.equals(this.login, other.login)) { + return false; + } + if (!Objects.equals(this.mdp, other.mdp)) { + return false; + } + if (!Objects.equals(this.adrRue, other.adrRue)) { + return false; + } + if (!Objects.equals(this.adrCP, other.adrCP)) { + return false; + } + if (!Objects.equals(this.adrVille, other.adrVille)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "Pompier{" + "id=" + id + ", idCaserne=" + idCaserne + ", nom=" + nom + ", prenom=" + prenom + ", statut=" + statut + ", mail=" + mail + ", login=" + login + ", mdp=" + mdp + ", adrNo=" + adrNo + ", adrRue=" + adrRue + ", adrCP=" + adrCP + ", adrVille=" + adrVille + ", grade=" + grade + '}'; + } + + +} diff --git a/src/java/com/test/beans/User.java b/src/java/com/test/beans/User.java new file mode 100644 index 0000000..a37cc0e --- /dev/null +++ b/src/java/com/test/beans/User.java @@ -0,0 +1,68 @@ +/* + * 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 com.test.beans; + +import java.util.Objects; + +/** + * + * @author clementine.desrucques + */ +public class User { + private String pseudo; + private String mdp; + + public User(String pseudo, String mdp) { + this.pseudo = pseudo; + this.mdp = mdp; + } + + public String getPseudo() { + return pseudo; + } + + public void setPseudo(String pseudo) { + this.pseudo = pseudo; + } + + public String getMdp() { + return mdp; + } + + public void setMdp(String mdp) { + this.mdp = mdp; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 67 * hash + Objects.hashCode(this.pseudo); + hash = 67 * hash + Objects.hashCode(this.mdp); + 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 User other = (User) obj; + if (!Objects.equals(this.pseudo, other.pseudo)) { + return false; + } + if (!Objects.equals(this.mdp, other.mdp)) { + return false; + } + return true; + } + +} diff --git a/src/java/com/test/forms/AuthentifForm.java b/src/java/com/test/forms/AuthentifForm.java new file mode 100644 index 0000000..ae27966 --- /dev/null +++ b/src/java/com/test/forms/AuthentifForm.java @@ -0,0 +1,55 @@ +/* + * 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 com.test.forms; + +import com.test.beans.User; +import jakarta.servlet.http.HttpServletRequest; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; +/** + * + * @author clementine.desrucques + */ +public class AuthentifForm { + private String resultat; + + public String getResultat() { + return resultat; + } + + public void setResultat(String resultat) { + this.resultat = resultat; + } + + /** + * Contôle si les paramètres ztPseudo et ztMDP passé dans request + * correspondent à ceux de l'addministrateur Mise à jour de l'attribut + * resultat + * + * @param request + * @return true is ok, false sinon + */ + public boolean controlerRole(HttpServletRequest request) { + /* Comparaison entre l'utilisateur admin et un utilisateur créé + avec le pseudo et le mdp saisi */ + User ChefCaserne = new User("Michel", "mRANN"); + User userSaisi = new User( request.getParameter("ztPseudo"), + request.getParameter("ztMDP")); + boolean isChef = userSaisi.equals(ChefCaserne); + + // Mise à jour de l'attribut resultat + setResultat(isChef ? "Vous êtes chef de caserne" : "Vous n'êtes pas chef de caserne"); + + return isChef; + } + + +} diff --git a/src/java/com/test/forms/NouveauPompForm.java b/src/java/com/test/forms/NouveauPompForm.java new file mode 100644 index 0000000..db4d698 --- /dev/null +++ b/src/java/com/test/forms/NouveauPompForm.java @@ -0,0 +1,76 @@ +/* + * 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 com.test.forms; + +import bdd.PompierMySql; +import com.mysql.cj.util.StringUtils; +import com.test.beans.Pompier; +import jakarta.servlet.http.HttpServletRequest; +import java.util.Enumeration; +import static jdk.vm.ci.sparc.SPARC.CPUFeature.MD5; + +/** + * + * @author clementine.desrucques + */ +public class NouveauPompForm { + String message=""; + + public int verifNouveauPompier(HttpServletRequest request) { + + // Contrôle du no de rue qui doit être numérique + String noRueString = request.getParameter("nAdrNo"); + boolean isNumeric = StringUtils.isStrictlyNumeric(noRueString); + if (!isNumeric) { + message = "Le no de rue doit être numérique"; + return -1; + } + int noRue = Integer.parseInt(noRueString); + + // Contrôle car "<" dans les zones de texte + //String [] lesSaisies = request.getParameterValues(noRueString); // Valeurs saisies + Enumeration lesNoms = request.getParameterNames(); + int erreur = 0; + while (erreur ==0 && lesNoms.hasMoreElements()) { + Object paramObjet=lesNoms.nextElement(); + String param=(String)paramObjet; + String value=request.getParameter(param); + if (value.contains("<")) { + message = "Veullez recommencer votre saisie, une anomalie sur une zone de saisie a été détectée "; + erreur=1; + } + } + if (erreur > 0) return -1; + +// Creation d'un objet de type Client avec les données transmises +// String mdpChiffre = MD5.encode(request.getParameter("ztMDP")); + 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"), + noRue, + request.getParameter("ztAdrRue"), + request.getParameter("ztAdrCP"), + request.getParameter("ztAdrVille"), + request.getParameter("nGrade") + ); + PompierMySql cm = new PompierMySql(); + int id = cm.createRP(unPompier); // Requête préparée + if (id == -1) { + message = "Erreur lors de la création du pompier"; + } + return id; + + } + + public String getMessage() { + return message; + } +} diff --git a/src/java/com/test/servlets/ChefCaserneServlet.java b/src/java/com/test/servlets/ChefCaserneServlet.java new file mode 100644 index 0000000..dd712ec --- /dev/null +++ b/src/java/com/test/servlets/ChefCaserneServlet.java @@ -0,0 +1,86 @@ +/* + * 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 com.test.servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/** + * + * @author funcha.ahamadi + */ +public class ChefCaserneServlet 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 ChefCaserneServlet"); + out.println(""); + out.println(""); + out.println("

Servlet ChefCaserneServlet 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); + } + + /** + * 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); + } + + /** + * 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/com/test/servlets/PompierServlet.java b/src/java/com/test/servlets/PompierServlet.java new file mode 100644 index 0000000..810e97d --- /dev/null +++ b/src/java/com/test/servlets/PompierServlet.java @@ -0,0 +1,86 @@ +/* + * 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 com.test.servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/** + * + * @author funcha.ahamadi + */ +public class PompierServlet 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 PompierServlet"); + out.println(""); + out.println(""); + out.println("

Servlet PompierServlet 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); + } + + /** + * 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); + } + + /** + * 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/com/test/servlets/authentifServlet.java b/src/java/com/test/servlets/authentifServlet.java new file mode 100644 index 0000000..8cfc568 --- /dev/null +++ b/src/java/com/test/servlets/authentifServlet.java @@ -0,0 +1,109 @@ +/* + * 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 com.test.servlets; + +import com.test.forms.AuthentifForm; +import java.io.IOException; +import java.io.PrintWriter; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +/** + * + * @author clementine.desrucques + */ +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 AccueilServlet"); + out.println(""); + out.println(""); + out.println("

Servlet AccueilServlet 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); + System.out.println("****blablabla****"); + HttpSession maSession = request.getSession(); + maSession.removeAttribute("isAuthentified"); + getServletContext().getRequestDispatcher("/WEB-INF/accueilJSP.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 { + // Création de l'objet leControle de type AuthentifForm + AuthentifForm leControle = new AuthentifForm(); + // Appel de la méthode controlerAdmin + boolean isChef = leControle.controlerRole(request); + // Création de 2 attributs de requête (isAdmin et leControle) + request.setAttribute("isChef", isChef); + request.setAttribute("controlForm", leControle); + HttpSession maSession = request.getSession(); + maSession.setAttribute("isAuthentified", true); + // Affichage de la JSP + if(isChef==true){ + getServletContext().getRequestDispatcher("/WEB-INF/ChefCaserneJSP.jsp") + .forward(request, response); + }else{ + getServletContext().getRequestDispatcher("/WEB-INF/PompierJSP.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/web/META-INF/context.xml b/web/META-INF/context.xml new file mode 100644 index 0000000..b8c4c34 --- /dev/null +++ b/web/META-INF/context.xml @@ -0,0 +1,2 @@ + + diff --git a/web/WEB-INF/ChefCaserneJSP.jsp b/web/WEB-INF/ChefCaserneJSP.jsp new file mode 100644 index 0000000..4c1501d --- /dev/null +++ b/web/WEB-INF/ChefCaserneJSP.jsp @@ -0,0 +1,17 @@ +<%-- + Document : ChefCaserneJSP + Created on : 18 oct. 2021, 11:04:13 + Author : funcha.ahamadi +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + Chef de caserne + + +

Hello World!

+ + diff --git a/web/WEB-INF/CreaPompier.jsp b/web/WEB-INF/CreaPompier.jsp new file mode 100644 index 0000000..bbf8795 --- /dev/null +++ b/web/WEB-INF/CreaPompier.jsp @@ -0,0 +1,47 @@ +<%-- + Document : CreaPompier + Created on : 18 oct. 2021, 15:49:36 + Author : clementine.desrucques +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + Nouveau Pompier + + +

Création d'un nouveau pompier

+
+ Fiche Pompier +
+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +
+
+ + diff --git a/web/WEB-INF/ModifPompier.jsp b/web/WEB-INF/ModifPompier.jsp new file mode 100644 index 0000000..ced54b1 --- /dev/null +++ b/web/WEB-INF/ModifPompier.jsp @@ -0,0 +1,17 @@ +<%-- + Document : ModifPompier + Created on : 18 oct. 2021, 15:49:00 + Author : clementine.desrucques +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + JSP Page + + +

Hello World!

+ + diff --git a/web/WEB-INF/PompierJSP.jsp b/web/WEB-INF/PompierJSP.jsp new file mode 100644 index 0000000..932b43f --- /dev/null +++ b/web/WEB-INF/PompierJSP.jsp @@ -0,0 +1,17 @@ +<%-- + Document : PompierJSP + Created on : 18 oct. 2021, 11:01:21 + Author : funcha.ahamadi +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + JSP Page + + +

Hello World!

+ + diff --git a/web/WEB-INF/accueilJSP.jsp b/web/WEB-INF/accueilJSP.jsp new file mode 100644 index 0000000..96f8760 --- /dev/null +++ b/web/WEB-INF/accueilJSP.jsp @@ -0,0 +1,33 @@ +<%-- + Document : accueilJSP + Created on : 18 oct. 2021, 10:56:46 + Author : clementine.desrucques +--%> +<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@page import="com.test.forms.AuthentifForm" %> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + +

Bienvenue

+${empty param.ztPseudo ? "Veuillez vous authentifier" : "Authentification réussie"} + + + +
+ Authentification +
+
+

+ +
+
+
+ + + +

${controlForm.getResultat()}

+
+
+ +
\ No newline at end of file diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml new file mode 100644 index 0000000..b9d7f13 --- /dev/null +++ b/web/WEB-INF/web.xml @@ -0,0 +1,32 @@ + + + + PompierServlet + com.test.servlets.PompierServlet + + + ChefCaserneServlet + com.test.servlets.ChefCaserneServlet + + + authentifServlet + com.test.servlets.authentifServlet + + + PompierServlet + /Pompier + + + ChefCaserneServlet + /ChefCaserne + + + authentifServlet + /Authentification + + + + 30 + + + diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..c627c24 --- /dev/null +++ b/web/index.html @@ -0,0 +1,16 @@ + + + + + TODO supply a title + + + + +
TODO write content
+ +