1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
/*
* 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 DTO;
import DAO.ConnecBDD;
import Models.Client;
import java.io.IOException;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
/**
*
* @author FixeFred
*/
public class ConnectClient implements Serializable {
//Objet Client
private Client client;
private String login;
private String mdp;
//Connexion BDD
protected static final Connection bdd = ConnecBDD.getInstance();
private GestionClient GestionClient;
/**
* Creates a new instance of connectClient
*/
public ConnectClient() {
}
//authentification client
public void connexionClient(ActionEvent event) throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
if (login.equals("admin") & mdp.equals("admin")) {
System.out.println("Connexion admin");
context.addMessage(null, new FacesMessage("Identifié", "Bonjour Admin"));
ec.redirect("./index.xhtml?faces-redirect=true");
} else {
System.out.println("Connexion client");
String sqlClient = "Select nom, prenom, adresse, code_postale, ville, telephone, mobile, mail, identifiant, mdp FROM client WHERE identifiant = '" + login + "'";
System.out.println(sqlClient);
try {
Statement state = this.bdd.createStatement();
ResultSet rs = state.executeQuery(sqlClient);
rs.first();
client = new Client(rs.getString(1), rs.getString(2), rs.getString(3), rs.getInt(4), rs.getString(5), rs.getInt(6), rs.getInt(7), rs.getString(8), rs.getString(9), rs.getString(10));
GestionClient.setClientActiv(client);
rs.close();
ec.redirect("./gestionClient.xhtml?faces-redirect=true");
context.addMessage(null, new FacesMessage("Identifié", "Bonjour " + GestionClient.getClientActiv().getPrenom()));
} catch (SQLException e) {
System.out.println("Erreur authentification client : " + e.getMessage());
context.addMessage(null, new FacesMessage("Erreur", "Authentification refusée"));
ec.redirect("./connexion.xhtml?faces-redirect=true");
}
}
}
/**
* @return the client
*/
public Client getClient() {
return client;
}
/**
* @param client the client to set
*/
public void setClient(Client client) {
this.client = client;
}
/**
* @return the login
*/
public String getLogin() {
return login;
}
/**
* @param adminLogin the login to set
*/
public void setLogin(String adminLogin) {
this.login = adminLogin;
}
/**
* @return the mdp
*/
public String getMdp() {
return mdp;
}
/**
* @param adminMdp the mdp to set
*/
public void setMdp(String adminMdp) {
this.mdp = adminMdp;
}
/**
* @return the gestionClient
*/
public GestionClient getGestionClient() {
return GestionClient;
}
/**
* @param gestionClient the gestionClient to set
*/
public void setGestionClient(GestionClient gestionClient) {
this.GestionClient = gestionClient;
}
} |
Partager