From d489cc683f55070bdeb0251347fe0f07f09407e0 Mon Sep 17 00:00:00 2001 From: "clementine.desrucques" Date: Mon, 18 Oct 2021 14:56:59 +0200 Subject: [PATCH] --- src/java/com/test/beans/User.java | 68 ++++++++++++++++++++++ src/java/com/test/forms/AuthentifForm.java | 39 +++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 src/java/com/test/beans/User.java 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 index a2eef5d..2eee6c0 100644 --- a/src/java/com/test/forms/AuthentifForm.java +++ b/src/java/com/test/forms/AuthentifForm.java @@ -5,10 +5,49 @@ */ 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 controlerAdmin(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 userSaisi = new User( request.getParameter("ztPseudo"), + request.getParameter("ztMDP")); + boolean isAdmin = userSaisi.equals(admin); + + // Mise à jour de l'attribut resultat + setResultat(isAdmin ? "Vous êtes administrateur" : "Vous n'êtes pas administrateur"); + + return isAdmin; + } }