mirror of https://github.com/01-edu/public.git
10 changed files with 10 additions and 623 deletions
@ -1,16 +0,0 @@
|
||||
objects = src/main.o src/system.o src/auth.o
|
||||
|
||||
atm : $(objects) |
||||
cc -o atm $(objects)
|
||||
|
||||
main.o : src/header.h |
||||
kbd.o : src/header.h |
||||
command.o : src/header.h |
||||
display.o : src/header.h |
||||
insert.o : src/header.h |
||||
search.o : src/header.h |
||||
files.o : src/header.h |
||||
utils.o : src/header.h |
||||
|
||||
clean : |
||||
rm -f $(objects)
|
@ -1,6 +0,0 @@
|
||||
Alice 0 10/10/2012 Africa 291321234 22432.52 saving |
||||
|
||||
Michel 2 2/5/2001 Portugal 123543455 10023.230000 fixed01 |
||||
|
||||
Michel 123 10/10/2020 UK 1234123 12345.30 saving |
||||
|
@ -1,2 +0,0 @@
|
||||
Alice q1w2e3r4t5y6 |
||||
Michel q1w2e3r4t5y6 |
@ -1,59 +0,0 @@
|
||||
#include <termios.h> |
||||
#include "header.h" |
||||
|
||||
char *USERS = "./data/users.txt"; |
||||
|
||||
void loginMenu(char a[50], char pass[50]) |
||||
{ |
||||
struct termios oflags, nflags; |
||||
|
||||
system("clear"); |
||||
printf("\n\n\n\t\t\t\t Bank Management System\n\t\t\t\t\t User Login:"); |
||||
scanf("%s", a); |
||||
|
||||
// disabling echo
|
||||
tcgetattr(fileno(stdin), &oflags); |
||||
nflags = oflags; |
||||
nflags.c_lflag &= ~ECHO; |
||||
nflags.c_lflag |= ECHONL; |
||||
|
||||
if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) |
||||
{ |
||||
perror("tcsetattr"); |
||||
return exit(1); |
||||
} |
||||
printf("\n\n\n\n\n\t\t\t\tEnter the password to login:"); |
||||
scanf("%s", pass); |
||||
|
||||
// restore terminal
|
||||
if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) |
||||
{ |
||||
perror("tcsetattr"); |
||||
return exit(1); |
||||
} |
||||
}; |
||||
|
||||
const char *getPassword(struct User u) |
||||
{ |
||||
FILE *fp; |
||||
struct User userChecker; |
||||
|
||||
if ((fp = fopen("./data/users.txt", "r")) == NULL) |
||||
{ |
||||
printf("Error! opening file"); |
||||
exit(1); |
||||
} |
||||
|
||||
while (fscanf(fp, "%s %s", userChecker.name, userChecker.password) != EOF) |
||||
{ |
||||
if (strcmp(userChecker.name, u.name) == 0) |
||||
{ |
||||
fclose(fp); |
||||
char *buff = userChecker.password; |
||||
return buff; |
||||
} |
||||
} |
||||
|
||||
fclose(fp); |
||||
return "no user found"; |
||||
} |
@ -1,37 +0,0 @@
|
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <string.h> |
||||
|
||||
struct Date |
||||
{ |
||||
int month, day, year; |
||||
}; |
||||
|
||||
// all fields for each record of an account
|
||||
struct Record |
||||
{ |
||||
char name[100]; |
||||
char country[100]; |
||||
int phone; |
||||
char accountType[10]; |
||||
int accountNbr; |
||||
double amount; |
||||
struct Date deposit; |
||||
struct Date withdraw; |
||||
}; |
||||
|
||||
struct User |
||||
{ |
||||
char name[50]; |
||||
char password[50]; |
||||
}; |
||||
|
||||
// authentication functions
|
||||
void loginMenu(char a[50], char pass[50]); |
||||
void registerMenu(char a[50], char pass[50]); |
||||
const char *getPassword(struct User u); |
||||
|
||||
// system function
|
||||
void createNewAcc(struct User u); |
||||
void mainMenu(struct User u); |
||||
void checkAllAccounts(struct User u); |
@ -1,104 +0,0 @@
|
||||
#include "header.h" |
||||
|
||||
void mainMenu(struct User u) |
||||
{ |
||||
int option; |
||||
system("clear"); |
||||
printf("\n\n\t\t======= ATM =======\n\n"); |
||||
printf("\n\t\t-->> Feel free to choose one of the options below <<--\n"); |
||||
printf("\n\t\t[1]- Create a new account\n"); |
||||
printf("\n\t\t[2]- Update information of account\n"); |
||||
printf("\n\t\t[3]- Check accounts\n"); |
||||
printf("\n\t\t[4]- Check list of owned account\n"); |
||||
printf("\n\t\t[5]- Make Transaction\n"); |
||||
printf("\n\t\t[6]- Remove existing account\n"); |
||||
printf("\n\t\t[7]- Transfer ownership\n"); |
||||
printf("\n\t\t[8]- Exit\n"); |
||||
scanf("%d", &option); |
||||
|
||||
switch (option) |
||||
{ |
||||
case 1: |
||||
createNewAcc(u); |
||||
break; |
||||
case 2: |
||||
// student TODO : add your **Update information of existing account** function
|
||||
// here
|
||||
break; |
||||
case 3: |
||||
// student TODO : add your **Check the details of existing accounts** function
|
||||
// here
|
||||
break; |
||||
case 4: |
||||
checkAllAccounts(u); |
||||
break; |
||||
case 5: |
||||
// student TODO : add your **Make transaction** function
|
||||
// here
|
||||
break; |
||||
case 6: |
||||
// student TODO : add your **Remove existing account** function
|
||||
// here
|
||||
break; |
||||
case 7: |
||||
// student TODO : add your **Transfer owner** function
|
||||
// here
|
||||
break; |
||||
case 8: |
||||
exit(1); |
||||
break; |
||||
default: |
||||
printf("Invalid operation!\n"); |
||||
} |
||||
}; |
||||
|
||||
void initMenu(struct User *u) |
||||
{ |
||||
int r = 0; |
||||
int option; |
||||
system("clear"); |
||||
printf("\n\n\t\t======= ATM =======\n"); |
||||
printf("\n\t\t-->> Feel free to login / register :\n"); |
||||
printf("\n\t\t[1]- login\n"); |
||||
printf("\n\t\t[2]- register\n"); |
||||
printf("\n\t\t[3]- exit\n"); |
||||
while (!r) |
||||
{ |
||||
scanf("%d", &option); |
||||
switch (option) |
||||
{ |
||||
case 1: |
||||
loginMenu(u->name, u->password); |
||||
if (strcmp(u->password, getPassword(*u)) == 0) |
||||
{ |
||||
printf("\n\nPassword Match!"); |
||||
} |
||||
else |
||||
{ |
||||
printf("\nWrong password!! or User Name\n"); |
||||
exit(1); |
||||
} |
||||
r = 1; |
||||
break; |
||||
case 2: |
||||
// student TODO : add your **Registration** function
|
||||
// here
|
||||
r = 1; |
||||
break; |
||||
case 3: |
||||
exit(1); |
||||
break; |
||||
default: |
||||
printf("Insert a valid operation!\n"); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
int main() |
||||
{ |
||||
struct User u; |
||||
|
||||
initMenu(&u); |
||||
mainMenu(u); |
||||
return 0; |
||||
} |
@ -1,161 +0,0 @@
|
||||
#include "header.h" |
||||
|
||||
const char *RECORDS = "./data/records.txt"; |
||||
|
||||
int getAccountFromFile(FILE *ptr, char name[50], struct Record *r) |
||||
{ |
||||
return fscanf(ptr, "%s %d %d/%d/%d %s %d %lf %s", |
||||
name, |
||||
&r->accountNbr, |
||||
&r->deposit.month, |
||||
&r->deposit.day, |
||||
&r->deposit.year, |
||||
r->country, |
||||
&r->phone, |
||||
&r->amount, |
||||
r->accountType) != EOF; |
||||
} |
||||
|
||||
void saveAccountToFile(FILE *ptr, char name[50], struct Record r) |
||||
{ |
||||
fprintf(ptr, "%s %d %d/%d/%d %s %d %.2lf %s\n\n", |
||||
name, |
||||
r.accountNbr, |
||||
r.deposit.month, |
||||
r.deposit.day, |
||||
r.deposit.year, |
||||
r.country, |
||||
r.phone, |
||||
r.amount, |
||||
r.accountType); |
||||
} |
||||
|
||||
void stayOrReturn(int notGood, void f(struct User u), struct User u) |
||||
{ |
||||
int option; |
||||
if (notGood == 0) |
||||
{ |
||||
system("clear"); |
||||
printf("\nâś– Record not found!!\n"); |
||||
invalid: |
||||
printf("\nEnter 0 to try again, 1 to return to main menu and 2 to exit:"); |
||||
scanf("%d", &option); |
||||
if (option == 0) |
||||
f(u); |
||||
else if (option == 1) |
||||
mainMenu(u); |
||||
else if (option == 2) |
||||
exit(0); |
||||
else |
||||
{ |
||||
printf("Insert a valid operation!\n"); |
||||
goto invalid; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
printf("\nEnter 1 to go to the main menu and 0 to exit:"); |
||||
scanf("%d", &option); |
||||
} |
||||
if (option == 1) |
||||
{ |
||||
system("clear"); |
||||
mainMenu(u); |
||||
} |
||||
else |
||||
{ |
||||
system("clear"); |
||||
exit(1); |
||||
} |
||||
} |
||||
|
||||
void success(struct User u) |
||||
{ |
||||
int option; |
||||
printf("\nâś” Success!\n\n"); |
||||
invalid: |
||||
printf("Enter 1 to go to the main menu and 0 to exit!\n"); |
||||
scanf("%d", &option); |
||||
system("clear"); |
||||
if (option == 1) |
||||
{ |
||||
mainMenu(u); |
||||
} |
||||
else if (option == 0) |
||||
{ |
||||
exit(1); |
||||
} |
||||
else |
||||
{ |
||||
printf("Insert a valid operation!\n"); |
||||
goto invalid; |
||||
} |
||||
} |
||||
|
||||
void createNewAcc(struct User u) |
||||
{ |
||||
struct Record r; |
||||
struct Record cr; |
||||
char userName[50]; |
||||
FILE *pf = fopen(RECORDS, "a+"); |
||||
|
||||
noAccount: |
||||
system("clear"); |
||||
printf("\t\t\t===== New record =====\n"); |
||||
|
||||
printf("\nEnter today's date(mm/dd/yyyy):"); |
||||
scanf("%d/%d/%d", &r.deposit.month, &r.deposit.day, &r.deposit.year); |
||||
printf("\nEnter the account number:"); |
||||
scanf("%d", &r.accountNbr); |
||||
|
||||
while (getAccountFromFile(pf, userName, &cr)) |
||||
{ |
||||
if (strcmp(userName, u.name) == 0 && cr.accountNbr == r.accountNbr) |
||||
{ |
||||
printf("âś– This Account already exists for this user\n\n"); |
||||
goto noAccount; |
||||
} |
||||
} |
||||
printf("\nEnter the country:"); |
||||
scanf("%s", r.country); |
||||
printf("\nEnter the phone number:"); |
||||
scanf("%d", &r.phone); |
||||
printf("\nEnter amount to deposit: $"); |
||||
scanf("%lf", &r.amount); |
||||
printf("\nChoose the type of account:\n\t-> saving\n\t-> current\n\t-> fixed01(for 1 year)\n\t-> fixed02(for 2 years)\n\t-> fixed03(for 3 years)\n\n\tEnter your choice:"); |
||||
scanf("%s", r.accountType); |
||||
|
||||
saveAccountToFile(pf, u.name, r); |
||||
|
||||
fclose(pf); |
||||
success(u); |
||||
} |
||||
|
||||
void checkAllAccounts(struct User u) |
||||
{ |
||||
char userName[100]; |
||||
struct Record r; |
||||
|
||||
FILE *pf = fopen(RECORDS, "r"); |
||||
|
||||
system("clear"); |
||||
printf("\t\t====== All accounts from user, %s =====\n\n", u.name); |
||||
while (getAccountFromFile(pf, userName, &r)) |
||||
{ |
||||
if (strcmp(userName, u.name) == 0) |
||||
{ |
||||
printf("_____________________\n"); |
||||
printf("\nAccount number:%d\nDeposit Date:%d/%d/%d \ncountry:%s \nPhone number:%d \nAmount deposited: $%.2f \nType Of Account:%s\n", |
||||
r.accountNbr, |
||||
r.deposit.day, |
||||
r.deposit.month, |
||||
r.deposit.year, |
||||
r.country, |
||||
r.phone, |
||||
r.amount, |
||||
r.accountType); |
||||
} |
||||
} |
||||
fclose(pf); |
||||
success(u); |
||||
} |
@ -1,95 +0,0 @@
|
||||
#### Functional |
||||
|
||||
##### Open the application and register a new user with the name `"Alice"` and the password `"q1w2e3r4t5y6"` |
||||
|
||||
###### Is this user saved in the file `"./data/users.txt"`, and if so are all credentials correct (name and password)? |
||||
|
||||
##### Open the application and register again the user `"Alice"`. |
||||
|
||||
###### Did it displayed an error message saying that this user already exists? |
||||
|
||||
##### Open the file `"./data/users.txt"`. |
||||
|
||||
###### Are all the user names unique? (ex: no repetition on the name Alice) |
||||
|
||||
##### Try and login as `"Alice"`. |
||||
|
||||
###### Was Alice able to enter the main menu? |
||||
|
||||
##### Try to create two accounts using the user Alice, then select the option `"Update information of account"` and select an account number that does not exist for Alice. |
||||
|
||||
###### Did the application displayed some kind of error message saying that this account does not exist? |
||||
|
||||
##### Resorting to the user Alice try and select the option `"Update information of account"` and select one of the accounts you created for Alice. |
||||
|
||||
###### Did the the application prompt a choice of updating the **phone number** or the **country**? |
||||
|
||||
##### Resorting to the user Alice try and select the option `"Update information of account"` and select one of the accounts you created for Alice. Then update the phone number of that account. |
||||
|
||||
###### Was the phone number of that account updated in the application and the file `"records.txt"`? |
||||
|
||||
##### Resorting to the user Alice try and select the option `"Update information of account"` and select one of the accounts you created for Alice. Then update the country of that account. |
||||
|
||||
###### Was the country of that account updated in the application and the file `"records.txt"`? |
||||
|
||||
##### Resorting to the user Alice try to create a new account with: date `"10/10/2012"` account number `"834213"`, country `"UK"`, phone number `"291231392"`, deposit amount $`"1001.20"`, type of account `"saving"`. Then select `"Check accounts"` choose the account you just created. |
||||
|
||||
###### Did the application displayed the account information and the gain of $5.84 of interest on day 10 of every moth? |
||||
|
||||
##### Resorting to the user Alice create again an account but with account number "320421" and type of account "fixed01" with the rest of the information as in the last account . Then select `"Check accounts"` and choose the account you just created. |
||||
|
||||
###### Did the application displayed the account information and the gain of $40.05 of interest on 10/10/2013? |
||||
|
||||
##### Resorting to the user Alice create again an account but with account number `"3214"` and type of account `"fixed02"` with the rest of the information as in the last account. Then select `"Check accounts"` and choose the account you just created. |
||||
|
||||
###### Did the application displayed the account information and the gain of $100.12 of interest on 10/10/2014? |
||||
|
||||
##### Resorting to the user Alice create again an account but with account number `"3212"` and type of account `"fixed03"` with the rest of the information as in the last account. Then select `"Check accounts"` and choose the account you just created. |
||||
|
||||
###### Did the application displayed the account information and the gain of $240.29 of interest on 10/10/2015? |
||||
|
||||
##### Resorting to the user Alice select the option `"Make transaction"`. Then choose the account with the id `"3212"` |
||||
|
||||
###### Are you able to choose between withdrawing or depositing? |
||||
|
||||
##### Resorting to the user Alice select the option `"Make transaction"`, choose the account with the id `"3212"`. Then try to withdraw money. |
||||
|
||||
###### Are you able to withdraw money? |
||||
|
||||
###### And if so, was the withdraw updated in the file `"records.txt"`? |
||||
|
||||
###### Is it not possible to withdraw an amount superior to your available balance? |
||||
|
||||
##### Try to deposit money into the account `"3212"`. |
||||
|
||||
###### Were you able to deposit money into this account? |
||||
|
||||
###### And if so did it update the file `"records.txt"`? |
||||
|
||||
##### Resorting to the user Alice try to select the option `"Remove existing account"` and remove the accounts `"834213"`, `"320421"` and `"3214"`. |
||||
|
||||
###### Can you confirm that those account were deleted, both in the application and file `"records.txt"`? |
||||
|
||||
##### Resorting to the user Alice select the option `"Remove existing account"` and try to remove and nonexisting account. |
||||
|
||||
###### Did the application prompt some type of error saying that the account does not exists? |
||||
|
||||
##### Create another user named `"Michel"`. Then by using Alice select the option `"transfer owner"` and try to transfer ownership of the account `"3212"` to Michel. |
||||
|
||||
###### Were you able to transfer the ownership of this account to Michel? And if so did it update both application and file `"records.txt"`? |
||||
|
||||
#### Bonus |
||||
|
||||
##### Open two terminals and login with two different users. Then transfer ownership of an account to the other user. |
||||
|
||||
###### +Was the user whom received the account notified instantly? |
||||
|
||||
###### +Did the student update the terminal interface? |
||||
|
||||
###### +Is the password saved in the file `"users.txt"` encrypted? |
||||
|
||||
###### +Did the student make their own Makefile? |
||||
|
||||
###### +Did the student add more features to the project? |
||||
|
||||
###### +Did the student optimise the code already given? |
Loading…
Reference in new issue