summaryrefslogtreecommitdiff
path: root/src/main/java/controlleur/Connexion.java
blob: 952382e0b0dc3a36cbcf01f1160440e4c104bb93 (plain)
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
package controlleur;

import java.sql.SQLException;
import java.util.ArrayList;

import javafx.stage.Stage;
import modele.Evenement;
import modele.User;
import vue.AfficheAccueil;
import vue.AfficheConnexionFailed;

public class Connexion {
	public static EvenementController eventC ;
	public static Evenement event ;
	public static void verif(String login, String mdp,Stage primaryStage) {
		
		login = login.trim();
		mdp = Integer.toString(mdp.hashCode());
		BDD conec = new BDD();
		
		getFirstEvent();
		
		ArrayList<Object> rendu = conec.selectUtilisateur(login, mdp);
		int id = conec.UtilisateurID(login, mdp);
		String role = conec.UtilisateurRole(login, mdp);
		//System.out.println(role);
		conec.close();
		
		try {
			if (login.equals(rendu.get(0))) {
				User session = new User(login,id,role);
				
				//primaryStage.close();
				AfficheAccueil.affiche(primaryStage,session);
			}
			else {
				System.out.println(rendu);
			}
		}
		catch(Exception e) {
			AfficheConnexionFailed.affiche(primaryStage);
		}
	}
	
	public static void getFirstEvent() {
		eventC = new EvenementController(); // = lit et prend toute la table "evenement'
    	event = new Evenement( // on prend le premier
	    		eventC.getNom_event().get(0),
				eventC.getNom_image().get(0),
				eventC.getDesc_event().get(0),
				eventC.getDate_event().get(0)
		);
	}
	
	public static void updatePseudo(String pseudo,int id) throws SQLException {
		BDD conec = new BDD();
		conec.updateUtilisateur(pseudo,id);
		conec.close();
	}
	public static void updateMdp(String mdp,int id) throws SQLException {
		BDD conec = new BDD();
		conec.updateMp(mdp,id);
		conec.close();
	}
	public static String selectMdp(int id) throws SQLException {
		BDD conec = new BDD();
		String mdp =conec.UtilisateurMdp(id);
		conec.close();
		return mdp;
	}
}