Browse Source

refactoring: removed unnecessary lines and changed variables to constants in the storeEmployeeData() given that the function doesnt modify them.

remotes/origin/feature/employees-infos-access
fdai7207 2 years ago
parent
commit
6ad040483c
  1. 36
      src/createEmployeeAccount.c
  2. 4
      src/createEmployeeAccount.h

36
src/createEmployeeAccount.c

@ -61,7 +61,9 @@ int StringLengthCounter(char* string)
return characterCounter; return characterCounter;
} }
bool storeEmployeeData(char *name,char *lastName,char *adress,char *phoneNumber)
/*changed the string parameters to constants as an indicator that the function doesnt modify them*/
bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber)
{ {
FILE* employeesDatalist; FILE* employeesDatalist;
employeesDatalist = fopen("src/employeesData.txt","a"); employeesDatalist = fopen("src/employeesData.txt","a");
@ -106,66 +108,54 @@ bool createNewEmployee(char* employeeId, char* employeePassword)
void getNewEmployeeCredentials() void getNewEmployeeCredentials()
{ {
employeedata *data;
data = (employeedata*)malloc(sizeof(employeedata));
employeedata *data = (employeedata*)malloc(sizeof(employeedata));
const int maxLength = 21; const int maxLength = 21;
char employeeId[maxLength]; char employeeId[maxLength];
const int minPasswordLength = 5; const int minPasswordLength = 5;
char employeePassword[maxLength]; char employeePassword[maxLength];
char passwordVerfication[maxLength]; char passwordVerfication[maxLength];
printf("please enter your wished Id :\n"); printf("please enter your wished Id :\n");
/*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/ /*Added the regular expression [^\n] so that the string keep on getting read until a newline '\n' is found*/
scanf(" %[^\n]s",employeeId); scanf(" %[^\n]s",employeeId);
employeeId[maxLength] = '\0'; employeeId[maxLength] = '\0';
printf("\nplease enter your wished Password :\n"); printf("\nplease enter your wished Password :\n");
scanf("%s",employeePassword); scanf("%s",employeePassword);
employeePassword[strlen(employeePassword)] = '\0'; employeePassword[strlen(employeePassword)] = '\0';
printf("\nplease confirm your Password :\n"); printf("\nplease confirm your Password :\n");
scanf("%s",passwordVerfication); scanf("%s",passwordVerfication);
passwordVerfication[strlen(employeePassword)] = '\0'; passwordVerfication[strlen(employeePassword)] = '\0';
if(verifyPassword(passwordVerfication,employeePassword) && isValidPassword(employeePassword,minPasswordLength) && isValidEmployeeID(employeeId,maxLength)) if(verifyPassword(passwordVerfication,employeePassword) && isValidPassword(employeePassword,minPasswordLength) && isValidEmployeeID(employeeId,maxLength))
{ {
printf("\n\nplease enter your first name\n"); printf("\n\nplease enter your first name\n");
scanf("%s",data->firstName); scanf("%s",data->firstName);
printf("\n\nplease enter your last name\n"); printf("\n\nplease enter your last name\n");
scanf("%s",data->lastName); scanf("%s",data->lastName);
printf("\n\nplease enter your adress\n"); printf("\n\nplease enter your adress\n");
scanf("%s",data->adress);
scanf("%s",data->address);
printf("\n\nplease enter your Phone number\n"); printf("\n\nplease enter your Phone number\n");
scanf("%s",data->phoneNumber); scanf("%s",data->phoneNumber);
createNewEmployee(employeeId,employeePassword) ? printf("\n\n Account created successfully !\n\n") : printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n");
createNewEmployee(employeeId,employeePassword) ?
printf("\n\n Account created successfully !\n\n") :
printf("\n\n Could not create the Account please contact an employee of clearance 1 !\n\n");
storeEmployeeData(data->firstName,data->lastName,data->adress,data->phoneNumber);
storeEmployeeData(data->firstName,data->lastName,data->address,data->phoneNumber);
} }
else else
{ {
printf("\n\nError! one of these conditions is not met in your input\n\n");
printf("\n-the entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol!\n");
printf("\n-the entered ID should contain a maximum of 20 letters!\n");
printf("\n-the verification password should match with the entered password.\n");
printf("\nError! one of these conditions is not met in your input.\n");
printf("\n-The entered password should be at least 5 characters long and should contain at least 1 digit, 1 alphabet and 1 symbol.\n");
printf("\n-The entered ID should contain a maximum of 20 letters.\n");
printf("\n-The verification password should match with the entered password.\n");
} }
} }

4
src/createEmployeeAccount.h

@ -11,7 +11,7 @@ struct employeesInformations
{ {
char firstName[15]; char firstName[15];
char lastName[15]; char lastName[15];
char adress[20];
char address[20];
char phoneNumber[15]; char phoneNumber[15];
}; };
typedef struct employeesInformations employeedata; typedef struct employeesInformations employeedata;
@ -20,7 +20,7 @@ bool isValidEmployeeID(const char* employee, int maximumLength);
bool isValidPassword( char* password, int minimumLength); bool isValidPassword( char* password, int minimumLength);
bool createNewEmployee(char* employeeId, char* employeePassword); bool createNewEmployee(char* employeeId, char* employeePassword);
bool verifyPassword(char* enteredPassword,char* passwordConfirmation); bool verifyPassword(char* enteredPassword,char* passwordConfirmation);
bool storeEmployeeData(char *name,char *lastName,char *adress,char *phoneNumber);
bool storeEmployeeData(const char *name,const char *lastName,const char *adress,const char *phoneNumber);
int StringLengthCounter(char* string); int StringLengthCounter(char* string);

Loading…
Cancel
Save