diff --git a/build-project.sh b/build-project.sh index 420b964..5988d59 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,6 +1,12 @@ clear ceedling test:all cd src/ +cp employeeLogin.c employeeLogin.c.bak +sed -i 's/src\///g' employeeLogin.c gcc main.c mainMenu.c -o main ./main rm main +cp employeeLogin.c.bak employeeLogin.c +rm employeeLogin.c.bak +cd .. +rm -r build/ diff --git a/project.yml b/project.yml index e253248..51a5a2a 100644 --- a/project.yml +++ b/project.yml @@ -35,6 +35,7 @@ - -:test/support :source: - src/** + - src/ :support: - test/support :libraries: [] diff --git a/src/employeeLogin.c b/src/employeeLogin.c index 542526f..624d0ae 100644 --- a/src/employeeLogin.c +++ b/src/employeeLogin.c @@ -1,22 +1,77 @@ +#include "mainMenu.h" #include "employeeLogin.h" -int checkEmployeeCredentials(char *inputUsername, char *inputPassword) +extern int checkEmployeeCredentials(char *inputUsername, char *inputPassword) { - char listUsername[credentialLength]; - char listPassword[credentialLength]; - - FILE *employeeList = fopen("src/employeeList.txt", "r"); - while (fscanf(employeeList, "%s %s", listUsername, listPassword) != EOF) { - if (strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) == 0) { - fclose(employeeList); - return 1; - } - else if(strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) != 0){ - fclose(employeeList); - return 2; - } - } - fclose(employeeList); - return 0; + char listUsername[credentialLength]; + char listPassword[credentialLength]; + + FILE* employeeList = fopen("src/employeeList.txt","r"); + + if(employeeList == NULL ) + { + printf("file does not exist"); + exit(1); + } + else + { + while (fscanf(employeeList, "%s %s", listUsername, listPassword) != EOF) + { + if (strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) == 0) + { + fclose(employeeList); + return 1; + } + else if(strcmp(inputUsername, listUsername) == 0 && strcmp(inputPassword, listPassword) != 0) + { + fclose(employeeList); + return 2; + } + } + fclose(employeeList); + return 0; + } +} + +void employeeCredentials(char* username,char* password) +{ + printf("Enter username: "); + scanf("%s", username); + printf("Enter password: "); + scanf("%s", password); +} + +void loginAsEmployee() +{ + int counter=2; + char username[credentialLength]; + char password[credentialLength]; + + employeeCredentials(username, password); + + while(counter>0) + { + if(checkEmployeeCredentials(username, password) == 0) + { + printf("User not found\n"); + employeeCredentials(username, password); + } + else if(checkEmployeeCredentials(username, password)==2) + { + printf("Wrong Informations !\nyou have %d tries left\n",counter); + employeeCredentials(username, password); + --counter; + } + else + { + printf("User Approved\n"); + break; + } + } + if(counter==0) + { + printf("you used up all of the tries! account locked\n"); + } + } diff --git a/src/employeeLogin.h b/src/employeeLogin.h index 6e4cb65..485955f 100644 --- a/src/employeeLogin.h +++ b/src/employeeLogin.h @@ -1,16 +1,13 @@ -#ifndef EMPLOYEELOGIN_H_ -#define EMPLOYEELOGIN_H_ +#ifndef LOGINEMPLOYEE_H_ +#define LOGINEMPLOYEE_H_ -#include -#include -#include -#include #define credentialLength 20 - - -int checkEmployeeCredentials(char* inputUsername , char* inputPassword); +int checkEmployeeCredentials(char* username , char* password); +void employeeCredentials(char* username, char* password); +void loginAsEmployee(); #endif + diff --git a/src/main b/src/main deleted file mode 100755 index fad988b..0000000 Binary files a/src/main and /dev/null differ diff --git a/src/main.c b/src/main.c index b37734e..7032d5b 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include "mainMenu.h" -int main() { +int main() +{ ageInput(); diff --git a/src/mainMenu.c b/src/mainMenu.c index 7b60ecf..f9f48a2 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -1,5 +1,6 @@ #include "mainMenu.h" +#include "employeeLogin.c" bool agePermission(int age) { @@ -76,8 +77,8 @@ void ageInput() } - } - + +} } void menuInput() @@ -106,7 +107,7 @@ void menuInput() case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n"); break; - case 3 : printf("\nLoginAsEmployee() function will be implemented here soon\n\n"); + case 3 : loginAsEmployee(); break; case 4 : printf("\e[1;1H\e[2J"); diff --git a/src/mainMenu.h b/src/mainMenu.h index 0824d42..17d81bc 100644 --- a/src/mainMenu.h +++ b/src/mainMenu.h @@ -6,6 +6,8 @@ #include #include +#define credentialLength 20 + bool agePermission(int age); bool checkIfInteger(char* userInput); bool chooseOption(int choiceInput);