-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·123 lines (115 loc) · 4.08 KB
/
main.cpp
File metadata and controls
executable file
·123 lines (115 loc) · 4.08 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
#include <string>
#include "AbstractUser.h"
#include "Exceptions.h"
#include "User.h"
#ifdef _WIN32
#define CLEAR "cls"
#else //In any other OS
#define CLEAR "clear"
#endif
using namespace std;
enum MenuState {
START,
LOGGED_IN,
END
};
int main() {
User::init("SECRET_KEY");
User * loggedInUser = nullptr;
MenuState menuState = MenuState::START;
string last_message;
char choice;
while(menuState != MenuState::END) {
system(CLEAR);
if (!last_message.empty())
cout << last_message << endl;
last_message = "";
switch (menuState) {
case MenuState::START: {
cout << "1. login\n2. signup\ne. exit\n";
cin >> choice;
switch (choice) {
case '1': { // login
try {
string username, password;
cout << "Enter Username: ";
cin >> username;
cout << "Enter Password: ";
cin >> password;
loggedInUser = &User::login(username,password);
menuState = MenuState::LOGGED_IN;
} catch (WrongUsernameOrPasswordException &e) {
last_message = e.what();
}
break;
}
case '2': { // signup
try {
string username, password, email;
cout << "Enter Email: ";
cin >> email;
cout << "Enter Username: ";
cin >> username;
cout << "Enter Password: ";
cin >> password;
loggedInUser = &User::signup(username, password, email);
menuState = MenuState::LOGGED_IN;
last_message = "User signed up!\n";
} catch (UsernameAlreadyExistsException &e) {
last_message = e.what();
break;
} catch (EmailAlreadyExistsException &e) {
last_message = e.what();
}
break;
}
case 'e': { // exit
menuState = MenuState::END;
break;
}
default: { // unknown input
last_message = "Unknown Input\n";
break;
}
}
break;
}
case MenuState::LOGGED_IN: {
cout << "d.delete account\nl. logout\ne. exit\n";
cin >> choice;
switch (choice) {
case 'd': {
try {
loggedInUser->deleteAccount();
cout << "Account successfully deleted\n";
loggedInUser = nullptr;
menuState = MenuState::START;
}
catch (DeleteAdminException &e) {
last_message = e.what();
}
break;
}
case 'l': { // logout
loggedInUser = nullptr;
menuState = MenuState::START;
last_message = "GOOD BYE\n";
break;
}
case 'e': { // exit
menuState = MenuState::END;
break;
}
default: { // unknown input
last_message = "Unknown Input\n";
break;
}
}
}
}
}
system(CLEAR);
cout << "GOODBYE" << endl;
return 0;
}