Update DBAppV2.cpp
This commit is contained in:
parent
dd4453c9aa
commit
5dffb83905
1 changed files with 209 additions and 64 deletions
273
DBAppV2.cpp
273
DBAppV2.cpp
|
@ -13,6 +13,8 @@ vector<Message> mesages;
|
|||
vector<Group> groups;
|
||||
vector<Article> articles;
|
||||
User currentUser;
|
||||
//bool isLoggedIn = false;
|
||||
vector<User> pendingAccounts; //accounts waiting to be approved by the admin
|
||||
|
||||
void goToBoard()
|
||||
{
|
||||
|
@ -23,17 +25,16 @@ void goToBoard()
|
|||
cout<<"0. Return to main menu"<<endl;
|
||||
cout<<"3. back to board menu"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
}
|
||||
|
||||
void boardList()
|
||||
{
|
||||
cout<<"\n\nShowing all boards:"<<endl;
|
||||
cout<<"\n\nShowing all boards:"<<endl;
|
||||
|
||||
|
||||
cout<<"0. Return to main menu"<<endl;
|
||||
cout<<"3. Return to board menu"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
cout<<"0. Return to main menu"<<endl;
|
||||
cout<<"3. Return to board menu"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
}
|
||||
|
||||
|
@ -50,15 +51,6 @@ void boardMenu()
|
|||
|
||||
}
|
||||
|
||||
void showGroups()
|
||||
{
|
||||
cout<<"Groups will be displayed soon"<<endl;
|
||||
|
||||
cout<<"\n0. Return to main menu"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
}
|
||||
|
||||
void createNewAccount(string n, string pass, string phone, string fax, string postal, bool admin)
|
||||
{
|
||||
User newUser(n,pass,phone,fax,postal,admin);
|
||||
|
@ -70,9 +62,18 @@ void createNewAccount(string n, string pass, string phone, string fax, string po
|
|||
{
|
||||
cout<<users[i].getName()<<endl;
|
||||
}
|
||||
cout<<"account successfully created!"<<endl;
|
||||
|
||||
}
|
||||
|
||||
void addToPendingList(string n, string pass, string phone, string fax, string postal, bool admin)
|
||||
{
|
||||
User newUser(n,pass,phone,fax,postal,admin);
|
||||
pendingAccounts.push_back(newUser);
|
||||
|
||||
cout<<"Account successfully requested, waiting for admin to approve"<<endl;
|
||||
|
||||
}
|
||||
|
||||
void newAccount()
|
||||
{
|
||||
|
@ -97,9 +98,9 @@ void newAccount()
|
|||
cout<<"Postal code: "<<endl;
|
||||
cin>>postal;
|
||||
|
||||
createNewAccount(n,pass,phone,fax,postal,false);
|
||||
addToPendingList(n,pass,phone,fax,postal,false);
|
||||
|
||||
|
||||
cout<<"account successfully created!"<<endl;
|
||||
|
||||
cout<<"\n8. Return to login menu"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
@ -111,10 +112,17 @@ void mainMenu()
|
|||
cout<<"\n\n***************"<<endl;
|
||||
cout<<"** Main Menu **"<<endl;
|
||||
cout<<"***************\n"<<endl;
|
||||
cout<<"10. View current users\n"<<endl;
|
||||
cout<<"\n6. Your account"<<endl;
|
||||
cout<<"5. Enter Command"<<endl;
|
||||
cout<<"4. Articles"<<endl;
|
||||
cout<<"3. Boards"<<endl;
|
||||
cout<<"2. Messages"<<endl;
|
||||
cout<<"1. Groups\n"<<endl;
|
||||
if (currentUser.confirmAdmin() == true)
|
||||
{
|
||||
cout<<"9. View pending account requests\n"<<endl;
|
||||
}
|
||||
cout<<"8. Logout\n"<<endl;
|
||||
cout<<"Enter choice: ";
|
||||
}
|
||||
|
@ -188,55 +196,59 @@ void startMenu()
|
|||
void changeUsername()
|
||||
{
|
||||
cout<<"Enter new username: "<<endl;
|
||||
string newName;
|
||||
cin >> newName;
|
||||
currentUser.setName(newName);
|
||||
//Have it update the relation here
|
||||
cout << "\nName successfully changed!\n" << endl;
|
||||
string userInput;
|
||||
cin.ignore();
|
||||
getline(cin, userInput);
|
||||
|
||||
//currentUser.setName(userInput);
|
||||
parse(userInput, engine);
|
||||
|
||||
mainMenu();
|
||||
}
|
||||
|
||||
void changePassword()
|
||||
{
|
||||
cout<<"Enter new password: "<<endl;
|
||||
string newPassword;
|
||||
cin >> newPassword;
|
||||
currentUser.setPassword(newPassword);
|
||||
//Have it update the relation here
|
||||
cout << "\nPassword successfully changed!\n" << endl;
|
||||
string userInput;
|
||||
cin.ignore();
|
||||
getline(cin, userInput);
|
||||
|
||||
//currentUser.setPassword(userInput);
|
||||
parse(userInput, engine);
|
||||
mainMenu();
|
||||
}
|
||||
|
||||
void changePhone()
|
||||
{
|
||||
cout<<"Enter new phone number: "<<endl;
|
||||
string newPhoneNumber;
|
||||
cin >> newPhoneNumber;
|
||||
currentUser.setPhone(newPhoneNumber);
|
||||
//Have it update the relation here
|
||||
cout << "\nPhone Number successfully changed!\n" << endl;
|
||||
string userInput;
|
||||
cin.ignore();
|
||||
getline(cin, userInput);
|
||||
|
||||
//currentUser.setPhone(userInput);
|
||||
parse(userInput, engine);
|
||||
mainMenu();
|
||||
}
|
||||
|
||||
void changeFax()
|
||||
{
|
||||
cout<<"Enter new fax number: "<<endl;
|
||||
string newFaxNumber;
|
||||
cin >> newFaxNumber;
|
||||
currentUser.setFax(newFaxNumber);
|
||||
//Have it update the relation here
|
||||
cout << "\nFax Number successfully changed!\n" << endl;
|
||||
cout<<"Enter new fax number: "<<endl;string userInput;
|
||||
cin.ignore();
|
||||
getline(cin, userInput);
|
||||
|
||||
//currentUser.setFax(userInput);
|
||||
parse(userInput, engine);
|
||||
mainMenu();
|
||||
}
|
||||
|
||||
void changePostal()
|
||||
{
|
||||
cout<<"Enter new fax number: "<<endl;
|
||||
string newPostalNumber;
|
||||
cin >> newPostalNumber;
|
||||
currentUser.setPostal(newPostalNumber);
|
||||
//Have it update the relation here
|
||||
cout << "\nPostal Number successfully changed!\n" << endl;
|
||||
cout<<"Enter new fax number: "<<endl;string userInput;
|
||||
cin.ignore();
|
||||
getline(cin, userInput);
|
||||
|
||||
//currentUser.setPostal(userInput);
|
||||
parse(userInput, engine);
|
||||
mainMenu();
|
||||
}
|
||||
|
||||
|
@ -292,9 +304,6 @@ void yourAccount()
|
|||
|
||||
void showMessages()
|
||||
{
|
||||
//Causing seg fault
|
||||
// Relation temp = engine.getTableFromName("Messages");
|
||||
//temp.display();
|
||||
cout<<"\n\n0. Return to main menu"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
|
@ -306,6 +315,136 @@ void showMessages()
|
|||
}
|
||||
}
|
||||
|
||||
void showBoards()
|
||||
{
|
||||
parse("SHOW Boards ;", engine);
|
||||
|
||||
cout<<"\n\n0. Return to main menu?"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
int choice;
|
||||
cin >> choice;
|
||||
switch(choice)
|
||||
{
|
||||
case 0: mainMenu(); break;
|
||||
}
|
||||
}
|
||||
|
||||
void showCurrentUsers()
|
||||
{
|
||||
|
||||
parse("SHOW Users ;", engine);
|
||||
|
||||
cout<<"\n\n0. Return to main menu?"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
int choice;
|
||||
cin >> choice;
|
||||
switch(choice)
|
||||
{
|
||||
case 0: mainMenu(); break;
|
||||
}
|
||||
}
|
||||
|
||||
void showArticles()
|
||||
{
|
||||
parse("SHOW Articles ;", engine);
|
||||
|
||||
cout<<"\n\n0. Return to main menu?"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
int choice;
|
||||
cin >> choice;
|
||||
switch(choice)
|
||||
{
|
||||
case 0: mainMenu(); break;
|
||||
}
|
||||
}
|
||||
|
||||
void showGroups()
|
||||
{
|
||||
parse("SHOW Groups ;", engine);
|
||||
|
||||
cout<<"\n\n0. Return to main menu?"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
int choice;
|
||||
cin >> choice;
|
||||
switch(choice)
|
||||
{
|
||||
case 0: mainMenu(); break;
|
||||
}
|
||||
}
|
||||
|
||||
void enterCommand()
|
||||
{
|
||||
|
||||
string userInput;
|
||||
cin.ignore();
|
||||
getline(cin, userInput);
|
||||
|
||||
parse(userInput, engine);
|
||||
|
||||
cout<<"\n\n0. Return to main menu?"<<endl;
|
||||
cout<<"\n\nEnter choice:";
|
||||
|
||||
int choice;
|
||||
cin >> choice;
|
||||
switch(choice)
|
||||
{
|
||||
case 0: mainMenu(); break;
|
||||
}
|
||||
}
|
||||
|
||||
void approvePending()
|
||||
{
|
||||
cout<<"\nEnter the user number to approve: "<<endl;
|
||||
int user;
|
||||
cin>>user;
|
||||
|
||||
//make it idiotProof for invalid input?
|
||||
|
||||
users.push_back(pendingAccounts[user]);
|
||||
pendingAccounts.erase(pendingAccounts.begin()+user);
|
||||
|
||||
|
||||
cout<<"Account approved!"<<endl;
|
||||
cout<<"\n\Enter 9 to go back to pending requestes"<<endl;
|
||||
|
||||
}
|
||||
|
||||
void rejectPending()
|
||||
{
|
||||
cout<<"\nEnter the user number to reject: "<<endl;
|
||||
int user;
|
||||
cin>>user;
|
||||
|
||||
//make it idiotProof for invalid input?
|
||||
|
||||
pendingAccounts.erase(pendingAccounts.begin()+user);
|
||||
|
||||
cout<<"Account rejected!"<<endl;
|
||||
cout<<"\nEnter 9 to go back to pending requestes"<<endl;
|
||||
|
||||
}
|
||||
|
||||
void displayPendingRequests()
|
||||
{
|
||||
cout<<"current pendings: "<<endl;
|
||||
for (int i = 0; i < pendingAccounts.size(); ++i)
|
||||
{
|
||||
cout<<i<<" "<<pendingAccounts[i].getName()<<endl;
|
||||
}
|
||||
cout<<"\n\n11. Approve pending"<<endl;
|
||||
cout<<"12. Reject pending"<<endl;
|
||||
cout<<"13. Go back to Main Menu"<<endl;
|
||||
cout<<"\n\nEnter choice: ";
|
||||
|
||||
//make it idiotProof?
|
||||
|
||||
}
|
||||
|
||||
|
||||
void eventHandler(int choice)
|
||||
{
|
||||
switch(choice)
|
||||
|
@ -313,22 +452,31 @@ void eventHandler(int choice)
|
|||
case 0: loginMenu(); break;
|
||||
case 1: showGroups(); break;
|
||||
case 2: showMessages(); break;
|
||||
case 3: boardMenu(); break;
|
||||
case 4: boardList(); break;
|
||||
case 5: goToBoard(); break;
|
||||
case 3: showBoards(); break;
|
||||
case 4: showArticles(); break;
|
||||
case 5: enterCommand(); break;
|
||||
case 6: yourAccount(); break;
|
||||
case 7: newAccount(); break;
|
||||
case 8: startMenu(); break;
|
||||
case 10: showCurrentUsers(); break;
|
||||
case 13: mainMenu(); break;
|
||||
if (currentUser.confirmAdmin() == true)
|
||||
{
|
||||
case 9: displayPendingRequests(); break;
|
||||
case 11: approvePending(); break;
|
||||
case 12: rejectPending(); break;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
//Hard Coded Sample Tuples
|
||||
User u0("JOHN_CENA", "UberWrestling", "111-222-3333", "444-555-6666", "76432", true);
|
||||
User u1("Lo Wang", "Rice", "098-765-4321", "454-455-1923", "45123", false);
|
||||
User u0("admin", "admin", "111-222-3333", "444-555-6666", "76432", true);
|
||||
User u1("Lo_Wang", "Rice", "098-765-4321", "454-455-1923", "45123", false);
|
||||
User u2("Duke", "Nukem", "123-456-7890", "464-555-5431", "12362", false);
|
||||
User u3("Caleb", "Blood", "107-293-4856", "474-655-3421", "42231", false);
|
||||
User u4("Taggert", "Green", "666-666-6666", "484-755-6317", "66666", false);
|
||||
|
@ -355,11 +503,7 @@ int main()
|
|||
userAttributes.push_back(userAt2);
|
||||
userAttributes.push_back(userAt3);
|
||||
userAttributes.push_back(userAt4);
|
||||
Relation userRelation("User Relation", userAttributes);
|
||||
|
||||
for(int i = 0 ; i < users.size(); ++i) {
|
||||
userRelation.insertTuple(users[i].getInfo());
|
||||
}
|
||||
//Relation userRelation("User Relation", userAttributes);
|
||||
|
||||
//Message Relation & Attributes
|
||||
Attribute messageAt1("Sender", "VARCHAR(20)", true);
|
||||
|
@ -371,11 +515,8 @@ int main()
|
|||
messageAttributes.push_back(messageAt2);
|
||||
messageAttributes.push_back(messageAt3);
|
||||
messageAttributes.push_back(messageAt4);
|
||||
Relation messageRelation("Messages", messageAttributes);
|
||||
|
||||
for(int i = 0 ; i < mesages.size(); ++i) {
|
||||
messageRelation.insertTuple(mesages[i].getInfo());
|
||||
}
|
||||
//Relation messageRelation("Messages", messageAttributes);
|
||||
|
||||
|
||||
//Board Relation & Attributes
|
||||
Attribute boardAt1("Name", "VARCHAR(20)", true);
|
||||
|
@ -385,7 +526,7 @@ int main()
|
|||
boardAttributes.push_back(boardAt1);
|
||||
boardAttributes.push_back(boardAt2);
|
||||
boardAttributes.push_back(boardAt3);
|
||||
Relation boardRelation("Board Relation", boardAttributes);
|
||||
//Relation boardRelation("Board Relation", boardAttributes);
|
||||
|
||||
//Group Relation & Attributes
|
||||
Attribute groupAt1("Name", "VARCHAR(20)", true);
|
||||
|
@ -403,7 +544,7 @@ int main()
|
|||
articleAttributes.push_back(articleAt1);
|
||||
articleAttributes.push_back(articleAt2);
|
||||
articleAttributes.push_back(articleAt3);
|
||||
Relation articleRelation("Article Relation", articleAttributes);
|
||||
//Relation articleRelation("Article Relation", articleAttributes);
|
||||
|
||||
|
||||
|
||||
|
@ -411,6 +552,8 @@ int main()
|
|||
cout<<"Welcome to our BBS "<<endl;
|
||||
cout<<"***************************************"<<endl;
|
||||
|
||||
parse("OPEN Users ;", engine);
|
||||
|
||||
eventHandler(8);
|
||||
|
||||
int choice;
|
||||
|
@ -421,5 +564,7 @@ int main()
|
|||
cin>>choice;
|
||||
eventHandler(choice);
|
||||
}
|
||||
|
||||
engine.save();
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue