This commit is contained in:
parent
a1e49b6c11
commit
d489cc683f
68
src/java/com/test/beans/User.java
Normal file
68
src/java/com/test/beans/User.java
Normal 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 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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user