-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
93 lines (82 loc) · 2.96 KB
/
main.cpp
File metadata and controls
93 lines (82 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "bankmanagement.h"
using namespace std;
using namespace utils;
using json = nlohmann::json;
// ------------ COMMON LOGIN FUNCTION ------------
void handleBankLogin(const BANK_USER_ROLES & role);
int main()
{
try {
unsigned short choice;
BANK_USER_ROLES role;
while(true){
system("clear");
cout << "\n=-=-=-=-=-= LOGIN =-=-=-=-=-=\n" << endl;
cout << " 1) Admin" << endl;
cout << " 2) Staff" << endl;
cout << " 3) Account Holder" << endl;
cout << " 0) EXIT" << endl;
scanNumber(choice, " Enter Choice: ");
switch (choice) {
case 0: exit(0);
case 1: role = ADMIN; break;
case 2: role = STAFF; break;
case 3: role = ACCOUNT_HOLDER; break;
default:
cout << "\n ERROR: INPUT IN RANGE 0-2" << endl;
getchar(); getchar();
continue;
}
handleBankLogin(role);
}
}
catch (const exception &error) {
displayCustomErrorMessage(__PRETTY_FUNCTION__, __FILE__, error.what());
return 1;
}
catch (...) {
displayCustomErrorMessage(__PRETTY_FUNCTION__, __FILE__);
return 1;
}
return 0;
}
/** **************************************************************************************
* @brief handles login operations.
* It handles the login operation of the system.
* Handles logins of Staff, Admin and Account Holder
* @param role is the value of type BANK_USER_ROLES(enum) that defines login roles/options.
* **************************************************************************************/
void handleBankLogin(const BANK_USER_ROLES &role)
{
system("clear");
try {
unique_ptr <Staff> staff = NULL;
unique_ptr <AccountHolder> accHolder = NULL;
string userid, password;
cout << "\n----------- "
<< (role == ADMIN ? "ADMIN": (role == STAFF ? "STAFF": "ACCOUNT HOLDER"))
<<" LOGIN -----------\n" << endl;
cout << " => Enter userid: ";
cin >> userid;
cout << " => Enter password: ";
cin >> password;
switch (role) {
case ADMIN: staff.reset(Admin::login(userid, password)); break;
case STAFF: staff.reset(Staff::login(userid, password)); break;
case ACCOUNT_HOLDER: accHolder.reset(AccountHolder::login(userid, password)); break;
}
if(staff){
staff->displayPanel(); // display panel(staff/admin) on successfull login
return;
} else if (accHolder){
accHolder->displayPanel();
return;
}
} catch (const exception &error) {
displayCustomErrorMessage(__PRETTY_FUNCTION__, __FILE__, error.what());
} catch (...) {
displayCustomErrorMessage(__PRETTY_FUNCTION__, __FILE__);
}
getc(stdin);
getc(stdin);
}