r
This commit is contained in:
@@ -27,7 +27,6 @@ public class ClientMysql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void createClient(Client newCli) {
|
public void createClient(Client newCli) {
|
||||||
String commande = "INSERT INTO client(nom, prenom, mail) VALUES (?, ?, ?)";
|
String commande = "INSERT INTO client(nom, prenom, mail) VALUES (?, ?, ?)";
|
||||||
|
|
||||||
|
|||||||
45
src/main/java/com/test/bdd/SalarieMySQL.java
Normal file
45
src/main/java/com/test/bdd/SalarieMySQL.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package com.test.bdd;
|
||||||
|
|
||||||
|
import com.test.beans.Salarie;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author emile.malcuit
|
||||||
|
*/
|
||||||
|
public class SalarieMySQL {
|
||||||
|
private Connection laConnexion = connexionSQL.getConnect("192.168.100.100", "bdclient", "adminClient", "admin");
|
||||||
|
|
||||||
|
public SalarieMySQL() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Salarie read(String nom, String mdp){
|
||||||
|
String commande = "SELECT * FROM salarie WHERE nom = ? and mdp = ?";
|
||||||
|
Salarie recherche = new Salarie();
|
||||||
|
|
||||||
|
try(PreparedStatement pstmt = laConnexion.prepareStatement(commande)){
|
||||||
|
pstmt.setString(1, nom);
|
||||||
|
pstmt.setString(2, mdp);
|
||||||
|
ResultSet resultQ = pstmt.executeQuery();
|
||||||
|
if(resultQ.next()){
|
||||||
|
recherche.setId(resultQ.getInt("id"));
|
||||||
|
recherche.setNom(resultQ.getString("nom"));
|
||||||
|
recherche.setMdp(resultQ.getString("mdp"));
|
||||||
|
recherche.setIsAdmin(resultQ.getBoolean("isAdmin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
System.err.println("Erreur lors de la recherche du salarie : " + ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return recherche;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
79
src/main/java/com/test/beans/Salarie.java
Normal file
79
src/main/java/com/test/beans/Salarie.java
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package com.test.beans;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author emile.malcuit
|
||||||
|
*/
|
||||||
|
public class Salarie {
|
||||||
|
private int id;
|
||||||
|
private String nom;
|
||||||
|
private String mdp;
|
||||||
|
private boolean isAdmin;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Salarie() {
|
||||||
|
}
|
||||||
|
|
||||||
|
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 getMdp() {
|
||||||
|
return mdp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMdp(String mdp) {
|
||||||
|
this.mdp = mdp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIsAdmin() {
|
||||||
|
return isAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsAdmin(boolean isAdmin) {
|
||||||
|
this.isAdmin = isAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final Salarie other = (Salarie) obj;
|
||||||
|
if (!Objects.equals(this.nom, other.nom)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Objects.equals(this.mdp, other.mdp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
||||||
*/
|
|
||||||
package com.test.beans;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author emile.malcuit
|
|
||||||
*/
|
|
||||||
public class User {
|
|
||||||
private String pseudo;
|
|
||||||
private String motDePasse;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public User(String pseudo, String motDePasse) {
|
|
||||||
this.pseudo = pseudo;
|
|
||||||
this.motDePasse = motDePasse;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getPseudo() {
|
|
||||||
return pseudo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPseudo(String pseudo) {
|
|
||||||
this.pseudo = pseudo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMotDePasse() {
|
|
||||||
return motDePasse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMotDePasse(String motDePasse) {
|
|
||||||
this.motDePasse = motDePasse;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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;
|
|
||||||
}
|
|
||||||
return Objects.equals(this.motDePasse, other.motDePasse);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.test.forms;
|
package com.test.forms;
|
||||||
|
|
||||||
import com.test.beans.User;
|
import com.test.beans.Salarie;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,13 +23,13 @@ public class AuthentifForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean controlerAdmin(HttpServletRequest request){
|
public boolean controlerAdmin(Salarie unSalarie){ //HttpServletRequest request
|
||||||
User admin = new User("Lovelace", "Ada");
|
//Salarie admin = new Salarie("Lovelace", "Ada");
|
||||||
String login = request.getParameter("user_name");
|
//String login = request.getParameter("user_name");
|
||||||
String mdp = request.getParameter("user_password");
|
//String mdp = request.getParameter("user_password");
|
||||||
User userSaisi = new User(login, mdp);
|
//Salarie userSaisi = new Salarie(login, mdp);
|
||||||
boolean retour = false;
|
boolean retour = false;
|
||||||
if(userSaisi.equals(admin)){
|
if(unSalarie.isIsAdmin()){
|
||||||
retour = true;
|
retour = true;
|
||||||
setResultat("Vous êtes administrateur");
|
setResultat("Vous êtes administrateur");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.test.servlets;
|
package com.test.servlets;
|
||||||
|
|
||||||
|
import com.test.bdd.SalarieMySQL;
|
||||||
|
import com.test.beans.Salarie;
|
||||||
import com.test.forms.AuthentifForm;
|
import com.test.forms.AuthentifForm;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@@ -74,13 +76,18 @@ public class AuthentifServlet extends HttpServlet {
|
|||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
//processRequest(request, response);
|
//processRequest(request, response);
|
||||||
|
|
||||||
AuthentifForm authent = new AuthentifForm();
|
//Recupération de l'éssaie de connexion
|
||||||
boolean isAdmin = authent.controlerAdmin(request);
|
String nom = request.getParameter("user_name");
|
||||||
String status = authent.getResultat();
|
String mdp = request.getParameter("user_password");
|
||||||
|
Salarie unSalarie = new SalarieMySQL().read(nom, mdp);
|
||||||
|
|
||||||
|
//Vérification des droits
|
||||||
|
AuthentifForm authent = new AuthentifForm();
|
||||||
|
boolean isAdmin = authent.controlerAdmin(unSalarie);
|
||||||
|
String status = authent.getResultat();
|
||||||
request.setAttribute("isAdmin", isAdmin);
|
request.setAttribute("isAdmin", isAdmin);
|
||||||
request.setAttribute("status", status);
|
request.setAttribute("status", status);
|
||||||
request.setAttribute("pseudo", request.getAttribute("user_name"));
|
request.setAttribute("pseudo", unSalarie.getNom());
|
||||||
|
|
||||||
getServletContext().getRequestDispatcher("/WEB-INF/AcceuilJSP.jsp").forward(request, response);
|
getServletContext().getRequestDispatcher("/WEB-INF/AcceuilJSP.jsp").forward(request, response);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user