Browse Source

implement the functions employeeCredentials() and loginAsEmployee() for employees to access their accounts.

remotes/origin/feature/the-main-menu
fdai7207 2 years ago
parent
commit
9c0a02dfbb
  1. 6
      build-project.sh
  2. 1
      project.yml
  3. 89
      src/employeeLogin.c
  4. 15
      src/employeeLogin.h
  5. BIN
      src/main
  6. 3
      src/main.c
  7. 5
      src/mainMenu.c
  8. 2
      src/mainMenu.h

6
build-project.sh

@ -1,6 +1,12 @@
clear clear
ceedling test:all ceedling test:all
cd src/ cd src/
cp employeeLogin.c employeeLogin.c.bak
sed -i 's/src\///g' employeeLogin.c
gcc main.c mainMenu.c -o main gcc main.c mainMenu.c -o main
./main ./main
rm main rm main
cp employeeLogin.c.bak employeeLogin.c
rm employeeLogin.c.bak
cd ..
rm -r build/

1
project.yml

@ -35,6 +35,7 @@
- -:test/support - -:test/support
:source: :source:
- src/** - src/**
- src/
:support: :support:
- test/support - test/support
:libraries: [] :libraries: []

89
src/employeeLogin.c

@ -1,22 +1,77 @@
#include "mainMenu.h"
#include "employeeLogin.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");
}
} }

15
src/employeeLogin.h

@ -1,16 +1,13 @@
#ifndef EMPLOYEELOGIN_H_
#define EMPLOYEELOGIN_H_
#ifndef LOGINEMPLOYEE_H_
#define LOGINEMPLOYEE_H_
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
#define credentialLength 20 #define credentialLength 20
int checkEmployeeCredentials(char* inputUsername , char* inputPassword);
int checkEmployeeCredentials(char* username , char* password);
void employeeCredentials(char* username, char* password);
void loginAsEmployee();
#endif #endif

BIN
src/main

3
src/main.c

@ -1,6 +1,7 @@
#include "mainMenu.h" #include "mainMenu.h"
int main() {
int main()
{
ageInput(); ageInput();

5
src/mainMenu.c

@ -1,5 +1,6 @@
#include "mainMenu.h" #include "mainMenu.h"
#include "employeeLogin.c"
bool agePermission(int age) bool agePermission(int age)
{ {
@ -76,8 +77,8 @@ void ageInput()
} }
}
}
} }
void menuInput() void menuInput()
@ -106,7 +107,7 @@ void menuInput()
case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n"); case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n");
break; break;
case 3 : printf("\nLoginAsEmployee() function will be implemented here soon\n\n");
case 3 : loginAsEmployee();
break; break;
case 4 : printf("\e[1;1H\e[2J"); case 4 : printf("\e[1;1H\e[2J");

2
src/mainMenu.h

@ -6,6 +6,8 @@
#include<stdbool.h> #include<stdbool.h>
#include<string.h> #include<string.h>
#define credentialLength 20
bool agePermission(int age); bool agePermission(int age);
bool checkIfInteger(char* userInput); bool checkIfInteger(char* userInput);
bool chooseOption(int choiceInput); bool chooseOption(int choiceInput);

Loading…
Cancel
Save