diff --git a/src/login.c b/src/login.c index 46015fa..9d6119e 100644 --- a/src/login.c +++ b/src/login.c @@ -1 +1,76 @@ #include "main.h" + +/** + * @brief Fonction de connexion + * @param clientID: Tableau des identifiants client + * @param isAdmin: Tableau des statuts Administrateur des clients + * @param tlog: Taille logique des Tableaux + * @return Est Admin ? (1 > Oui, 0 > Non, -1 > Quitter) +*/ +int login(int clientID[], int isAdmin[], int tlog) +{ + int id, index, found, tentative=3; + printf("Entrez votre identifiant: "); + scanf("%d%*c", &id); + while (id < 0) + { + printf("Erreur, l'identifiant doit être positif, entrez votre identifiant: "); + scanf("%d%*c", &id); + } + index = searchTab(clientID, id, tlog, &found); + printf("%d",found); + while(found == 0) + { + printf("Erreur, l'identifiant n'existe pas, entrez votre identifiant: "); + scanf("%d%*c", &id); + if (id == 0) + { + return -1; + } + // Nombre de tentatives restantes + tentative--; + if (tentative == 0) + { + printf("Nombre de tentatives dépassé, retour au menu principal.\n"); + return -1; + } + index = searchTab(clientID, id, tlog, &found); + } + if (isAdmin[index] == 1) + { + return 1; + } + else + { + return 0; + } +} + +int signup(int clientID[], float cagnotte[], int suspended[], int isAdmin[], int *tlog) +{ + int id, index, found; + printf("Entrez votre identifiant: "); + scanf("%d%*c", &id); + while (id < 0) + { + printf("Erreur, l'identifiant doit être positif, entrez votre identifiant: "); + scanf("%d%*c", &id); + } + index = searchTab(clientID, id, *tlog, &found); + while(found == 1) + { + printf("Erreur, l'identifiant existe déjà, entrez votre identifiant: "); + scanf("%d%*c", &id); + if (id == 0) + { + return -1; + } + index = searchTab(clientID, id, *tlog, &found); + } + clientID[*tlog] = id; + cagnotte[*tlog] = 0; + suspended[*tlog] = 0; + isAdmin[*tlog] = 0; + *tlog ++; + return 0; +} \ No newline at end of file