From b184477f433794271ec58f6e84fc8722666d6ecd Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Wed, 11 Jan 2023 15:20:55 +0100 Subject: [PATCH] Fonction de connection totalement valide (en attente d'une fonction de chargement valide) --- donnees/log.don | 10 ++++---- header/sae.h | 5 +++- source/sae.c | 64 ++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/donnees/log.don b/donnees/log.don index 1f1dd0d..711a555 100644 --- a/donnees/log.don +++ b/donnees/log.don @@ -1,5 +1,5 @@ -yadahmaneb Code1 -loobry Code2 -gurey Code3 -andeamorin Code4 -jemarcillac Code5 \ No newline at end of file +yadahmaneb Code1 admin +loobry Code2 admin +gurey Code3 admin +andeamorin Code4 admin +jemarcillac Code5 admin \ No newline at end of file diff --git a/header/sae.h b/header/sae.h index 7914192..1c7de09 100644 --- a/header/sae.h +++ b/header/sae.h @@ -58,6 +58,7 @@ typedef struct log { char utilisateur[30]; char mdp[30]; + char status[15]; }Log; typedef struct maillonDept @@ -90,17 +91,19 @@ typedef struct // sae.c void testJean(void); + void Globale(void); Log * chargementLog(char * nomFichier, int * nbLog); int existeUtilisateur(char * utilisateur, int * indice, Log * tLog, int nbLog); int mdpValide(char * mdp, int indice, Log * tLog); //void menuVisiteur(VilleIut *villeIut, int nbVilles); -void menuVisiteur(Log * tLog); +void menuVisiteur(Log * tLog, int nbLog, VilleIut *tIut[], int nbVilles); int afficherMenuVisiteur(void); int choixMenuVisiteur(void); void banniereConnection(void); void saisieNomUtilisateur(char * utilisateur); void saisieMdp(char * mdp); +void seConnecter(Log * tLog, int nbLog); void seConnecterTest(void); int modifiePlacesDept(VilleIut *villeIut, int nbVilles, char *ville, char *nomDept, int nbP); diff --git a/source/sae.c b/source/sae.c index 1675183..54fbf32 100644 --- a/source/sae.c +++ b/source/sae.c @@ -15,13 +15,17 @@ void Globale(void) { Log * tLog; + VilleIut *tIut[50] ; + + int nbVilles; int nbLog; //Chargement des fichiers tLog = chargementLog("../donnees/log.don", &nbLog); + nbVilles = chargIutDon(tIut, 50, "../donnees/iut.don"); //Appel du menu visiteur - menuVisiteur(tLog); + menuVisiteur(tLog, nbLog, tIut, nbVilles); //Sauvegarde dans les fichiers } @@ -71,7 +75,8 @@ Log * chargementLog(char * nomFichier, int * nbLog) nbLogMax+= 5; } - fscanf(fichier, "%s %s", tLog[i].utilisateur, tLog[i].mdp); + fscanf(fichier, "%s %s %s", tLog[i].utilisateur, tLog[i].mdp, tLog[i].status); + printf("%s\n", tLog[i].status); i++; } @@ -79,13 +84,21 @@ Log * chargementLog(char * nomFichier, int * nbLog) return tLog; } +/*void test(VilleIut * tIut[], int nbVilles) +{ + for (int i = 0 ; i nom); + } +}*/ + /** * @brief Cette fonction affiche le menu des options disponibles pour un visiteur * et demande à l'utilisateur de faire son choix en appelant la fonction * choixMenuVisiteur. Selon le choix de l'utilisateur, la fonction appelle la fonction correspondante * ou met fin à l'exécution de la fonction. */ -void menuVisiteur(Log * tLog) +void menuVisiteur(Log * tLog, int nbLog, VilleIut *tIut[], int nbVilles) //void menuVisiteur(VilleIut *villeIut, int nbVilles) { int choix; @@ -100,8 +113,9 @@ void menuVisiteur(Log * tLog) switch(choix) { case 1: - //afficheVillesIUT(villeIut, 0); - printf("Affiche les villes qui ont des IUT. (En attente de la fonction de chargement)\n"); + //test(tIut, nbVilles); + //afficheVillesIUT(tIut, nbVilles); + printf("Affiche les Villes contenant des IUT (En attente d'une fonction de chargement fonctionnelle)\n"); break; case 2: printf("Affiche le nombre de place dans un departement (En attente de Guillaume)\n"); @@ -113,7 +127,7 @@ void menuVisiteur(Log * tLog) printf("Affiche les IUT possedant un departement donne (En attente de Jean)\n"); break; case 5 : - seConnecterTest(); + seConnecter(tLog, nbLog); clean break; case 0 : @@ -205,12 +219,46 @@ void seConnecterTest(void) saisieNomUtilisateur(utilisateur); // Récupération du nom d'utilisateur existe = existeUtilisateur(utilisateur, &indice, tLog, nbLog); - + saisieMdp(mdp); // Récupération du mot de passe valide = mdpValide(mdp, indice, tLog); } + +void seConnecter(Log * tLog, int nbLog) +{ + char mdp[30], utilisateur[30]; + int existe, indice, valide; + + banniereConnection(); // Affichage + saisieNomUtilisateur(utilisateur); // Récupération du nom d'utilisateur + + existe = existeUtilisateur(utilisateur, &indice, tLog, nbLog); + if(!existe) + { + printf("Utilisateur inexistant !\nAppuyez sur [entrée] pour continuer..."); + scanf("%*c"); + return; + } + + saisieMdp(mdp); + + valide = mdpValide(mdp, indice, tLog); + + if(valide) + { + printf("Connection valide en tant que %s\n", tLog[indice].status); + printf("En attente de la fonction chargement\n"); + scanf("%*c"); + } + else + { + printf("Mot de passe invalide\nAppuyez sur [entrée] pour continuer..."); + scanf("%*c"); + } +} + /** * @brief Vérifie si un utilisateur existe dans le tableau de structures de log. * @@ -399,7 +447,7 @@ void menuAdmin(VilleIut *villeIut, int nbVilles) printf("\nVotre choix: "); // Saisie du choix de l'utilisateur - scanf("%d", &choix); + scanf("%d%*c", &choix); // Traitement du choix de l'utilisateur switch (choix)