Compare commits

...

4 Commits

Author SHA1 Message Date
funcha.ahamadi
9b5e26f37e V2 funcha 2021-10-19 08:42:39 +02:00
funcha.ahamadi
41dd372a13 V2 funcha 2021-10-18 17:11:20 +02:00
clementine.desrucques
07f93f329f 2021-10-18 16:33:00 +02:00
clementine.desrucques
9c8ff01a79 2021-10-18 15:51:58 +02:00
12 changed files with 263 additions and 28 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
/build/
/dist/
/nbproject/private/

View File

@@ -43,7 +43,7 @@ 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.platform.classpath=${j2ee.server.domain}/lib/annotations-api.jar:${j2ee.server.domain}/lib/catalina-ant.jar:${j2ee.server.domain}/lib/catalina-ha.jar:${j2ee.server.domain}/lib/catalina-ssi.jar:${j2ee.server.domain}/lib/catalina-storeconfig.jar:${j2ee.server.domain}/lib/catalina-tribes.jar:${j2ee.server.domain}/lib/catalina.jar:${j2ee.server.domain}/lib/ecj-4.20.jar:${j2ee.server.domain}/lib/el-api.jar:${j2ee.server.domain}/lib/jakartaee-migration-1.0.0-shaded.jar:${j2ee.server.domain}/lib/jasper-el.jar:${j2ee.server.domain}/lib/jasper.jar:${j2ee.server.domain}/lib/jaspic-api.jar:${j2ee.server.domain}/lib/jsp-api.jar:${j2ee.server.domain}/lib/servlet-api.jar:${j2ee.server.domain}/lib/tomcat-api.jar:${j2ee.server.domain}/lib/tomcat-coyote.jar:${j2ee.server.domain}/lib/tomcat-dbcp.jar:${j2ee.server.domain}/lib/tomcat-i18n-cs.jar:${j2ee.server.domain}/lib/tomcat-i18n-de.jar:${j2ee.server.domain}/lib/tomcat-i18n-es.jar:${j2ee.server.domain}/lib/tomcat-i18n-fr.jar:${j2ee.server.domain}/lib/tomcat-i18n-ja.jar:${j2ee.server.domain}/lib/tomcat-i18n-ko.jar:${j2ee.server.domain}/lib/tomcat-i18n-pt-BR.jar:${j2ee.server.domain}/lib/tomcat-i18n-ru.jar:${j2ee.server.domain}/lib/tomcat-i18n-zh-CN.jar:${j2ee.server.domain}/lib/tomcat-jdbc.jar:${j2ee.server.domain}/lib/tomcat-jni.jar:${j2ee.server.domain}/lib/tomcat-util-scan.jar:${j2ee.server.domain}/lib/tomcat-util.jar:${j2ee.server.domain}/lib/tomcat-websocket.jar:${j2ee.server.domain}/lib/websocket-api.jar
j2ee.server.type=Tomcat
jar.compress=false
javac.classpath=\

View File

@@ -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;
}
}

View File

@@ -0,0 +1,120 @@
/*
* 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;
/**
*
* @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;
}
}

View File

@@ -26,6 +26,11 @@ public class Pompier {
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;
@@ -41,10 +46,6 @@ public class Pompier {
this.grade = 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 int getId() {
return id;

View File

@@ -37,17 +37,19 @@ public class AuthentifForm {
* @param request
* @return true is ok, false sinon
*/
public boolean controlerAdmin(HttpServletRequest request) {
public boolean controlerRole(HttpServletRequest request) {
/* Comparaison entre l'utilisateur admin et un utilisateur créé
avec le pseudo et le mdp saisi */
User admin = new User("Love", "Ada");
User ChefCaserne = new User("Michel", "mRANN");
User userSaisi = new User( request.getParameter("ztPseudo"),
request.getParameter("ztMDP"));
boolean isAdmin = userSaisi.equals(admin);
boolean isChef = userSaisi.equals(ChefCaserne);
// Mise à jour de l'attribut resultat
setResultat(isAdmin ? "Vous êtes administrateur" : "Vous n'êtes pas administrateur");
return isAdmin;
setResultat(isChef ? "Vous êtes chef de caserne" : "Vous n'êtes pas chef de caserne");
return isChef;
}
}

View File

@@ -5,6 +5,7 @@
*/
package com.test.forms;
import bdd.PompierMySql;
import com.mysql.cj.util.StringUtils;
import com.test.beans.Pompier;
import jakarta.servlet.http.HttpServletRequest;
@@ -44,7 +45,8 @@ public class NouveauPompForm {
if (erreur > 0) return -1;
// Creation d'un objet de type Client avec les données transmises
Pompier unPompier = new Pompier(request.getParameter("idCaserne"),
Pompier unPompier = new Pompier(
request.getParameter("idCaserne"),
request.getParameter("ztNom"),
request.getParameter("ztPrenom"),
request.getParameter("statut"),
@@ -55,13 +57,14 @@ public class NouveauPompForm {
request.getParameter("ztRue"),
request.getParameter("ztCP"),
request.getParameter("ztVille"),
request.getParameter("grade"));
ClientMysql cm = new ClientMysql();
int idClient = cm.createRP(unPompier); // Requête préparée
if (idClient == -1) {
message = "Erreur lors de la création du client";
request.getParameter("grade")
);
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 idClient;
return id;
}

View File

@@ -78,15 +78,21 @@ public class authentifServlet extends HttpServlet {
// Création de l'objet leControle de type AuthentifForm
AuthentifForm leControle = new AuthentifForm();
// Appel de la méthode controlerAdmin
boolean isAdmin = leControle.controlerAdmin(request);
boolean isChef = leControle.controlerRole(request);
// Création de 2 attributs de requête (isAdmin et leControle)
request.setAttribute("isAdmin", isAdmin);
request.setAttribute("isChef", isChef);
request.setAttribute("controlForm", leControle);
HttpSession maSession = request.getSession();
maSession.setAttribute("isAuthentified", true);
// Affichage de la JSP
getServletContext().getRequestDispatcher("/WEB-INF/accueilJSP.jsp")
if(isChef==true){
getServletContext().getRequestDispatcher("/WEB-INF/ChefCaserneJSP.jsp")
.forward(request, response);
}else{
getServletContext().getRequestDispatcher("/WEB-INF/PompierJSP.jsp")
.forward(request, response);
}
}
/**

View File

@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/ProjetSDIS29_2/Authentification"/>
<Context path="/ProjetSDIS29_2"/>

View File

@@ -0,0 +1,17 @@
<%--
Document : CreaPompier
Created on : 18 oct. 2021, 15:49:36
Author : clementine.desrucques
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>

View File

@@ -0,0 +1,17 @@
<%--
Document : ModifPompier
Created on : 18 oct. 2021, 15:49:00
Author : clementine.desrucques
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>

View File

@@ -9,20 +9,20 @@
<servlet-class>com.test.servlets.ChefCaserneServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>AuthentifServlet</servlet-name>
<servlet-class>com.test.servlets.AuthentifServlet</servlet-class>
<servlet-name>authentifServlet</servlet-name>
<servlet-class>com.test.servlets.authentifServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PompierServlet</servlet-name>
<url-pattern>/PompierServlet</url-pattern>
<url-pattern>/Pompier</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ChefCaserneServlet</servlet-name>
<url-pattern>/ChefCaserneServlet</url-pattern>
<url-pattern>/ChefCaserne</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AuthentifServlet</servlet-name>
<url-pattern>/Authentification</url-pattern>
<servlet-name>authentifServlet</servlet-name>
<url-pattern>/authentification</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>