2015-10-06 00:00:26 -05:00
|
|
|
//#include <iostream>
|
|
|
|
#include "User.h"
|
2015-10-06 12:19:01 -05:00
|
|
|
#include "Parser.h"
|
|
|
|
#include "DBEngine.h"
|
2015-10-01 13:38:24 -05:00
|
|
|
|
2015-09-29 22:49:18 -05:00
|
|
|
using namespace std;
|
|
|
|
|
2015-10-06 12:19:01 -05:00
|
|
|
//Global objects used through the app
|
|
|
|
DBEngine engine;
|
2015-10-06 00:00:26 -05:00
|
|
|
vector<User> users;
|
2015-10-06 12:19:01 -05:00
|
|
|
vector<Board> boards;
|
|
|
|
vector<Message> mesages;
|
|
|
|
vector<Group> groups;
|
|
|
|
vector<Article> articles;
|
|
|
|
User currentUser;
|
2015-09-29 22:49:18 -05:00
|
|
|
|
|
|
|
void goToBoard()
|
|
|
|
{
|
2015-10-01 13:38:24 -05:00
|
|
|
cout<<"*********************************"<<endl;
|
2015-09-29 22:49:18 -05:00
|
|
|
cout<<"Board x"<<endl;
|
2015-10-01 13:38:24 -05:00
|
|
|
cout<<"*********************************\n"<<endl;
|
|
|
|
|
2015-09-29 22:49:18 -05:00
|
|
|
cout<<"0. Return to main menu"<<endl;
|
2015-10-01 13:38:24 -05:00
|
|
|
cout<<"3. back to board menu"<<endl;
|
2015-09-29 22:49:18 -05:00
|
|
|
cout<<"\n\nEnter choice:";
|
2015-09-29 23:06:39 -05:00
|
|
|
|
2015-09-29 22:49:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void boardList()
|
|
|
|
{
|
2015-10-01 13:38:24 -05:00
|
|
|
cout<<"\n\nShowing all boards:"<<endl;
|
|
|
|
|
|
|
|
|
2015-09-29 22:49:18 -05:00
|
|
|
cout<<"0. Return to main menu"<<endl;
|
2015-10-01 13:38:24 -05:00
|
|
|
cout<<"3. Return to board menu"<<endl;
|
2015-09-29 22:49:18 -05:00
|
|
|
cout<<"\n\nEnter choice:";
|
2015-09-29 23:06:39 -05:00
|
|
|
|
2015-09-29 22:49:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 13:38:24 -05:00
|
|
|
void boardMenu()
|
2015-09-29 22:49:18 -05:00
|
|
|
{
|
2015-10-01 13:38:24 -05:00
|
|
|
cout<<"*********************************"<<endl;
|
|
|
|
cout<<"Board Menu"<<endl;
|
|
|
|
cout<<"*********************************\n"<<endl;
|
|
|
|
cout<<"\n\n4. List of boards"<<endl;
|
|
|
|
cout<<"5. Go to board (enter shortcut[first few characters])"<<endl;
|
2015-09-29 22:49:18 -05:00
|
|
|
cout<<"0. Return to main menu"<<endl;
|
|
|
|
cout<<"\n\nEnter choice:";
|
2015-10-01 13:38:24 -05:00
|
|
|
|
2015-09-29 22:49:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void showGroups()
|
|
|
|
{
|
|
|
|
cout<<"Groups will be displayed soon"<<endl;
|
2015-10-01 13:38:24 -05:00
|
|
|
|
|
|
|
cout<<"\n0. Return to main menu"<<endl;
|
|
|
|
cout<<"\n\nEnter choice:";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-06 00:00:26 -05:00
|
|
|
void createNewAccount(string n, string pass, string phone, string fax, string postal, bool admin)
|
|
|
|
{
|
|
|
|
User newUser(n,pass,phone,fax,postal,admin);
|
|
|
|
users.push_back(newUser);
|
|
|
|
|
|
|
|
cout<<"current users:"<<endl;
|
|
|
|
|
|
|
|
for(int i = 0; i < users.size(); ++i)
|
|
|
|
{
|
|
|
|
cout<<users[i].getName()<<endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 13:38:24 -05:00
|
|
|
void newAccount()
|
|
|
|
{
|
|
|
|
cout<<"*********************************"<<endl;
|
|
|
|
cout<<"Request new account"<<endl;
|
|
|
|
cout<<"*********************************\n"<<endl;
|
2015-10-06 00:00:26 -05:00
|
|
|
|
|
|
|
string n, pass, phone, fax, postal;
|
|
|
|
|
|
|
|
cout<<"Name: "<<endl;
|
|
|
|
cin>>n;
|
|
|
|
|
|
|
|
cout<<"\nPassword: "<<endl;
|
|
|
|
cin>>pass;
|
|
|
|
|
|
|
|
cout<<"\nPhone: "<<endl;
|
|
|
|
cin>>phone;
|
|
|
|
|
|
|
|
cout<<"\nFax: "<<endl;
|
|
|
|
cin>>fax;
|
|
|
|
|
|
|
|
cout<<"Postal code: "<<endl;
|
|
|
|
cin>>postal;
|
|
|
|
|
|
|
|
createNewAccount(n,pass,phone,fax,postal,false);
|
|
|
|
|
|
|
|
cout<<"account successfully created!"<<endl;
|
|
|
|
|
2015-10-01 13:38:24 -05:00
|
|
|
cout<<"\n8. Return to login menu"<<endl;
|
2015-09-29 22:49:18 -05:00
|
|
|
cout<<"\n\nEnter choice:";
|
2015-09-29 23:06:39 -05:00
|
|
|
|
2015-09-29 22:49:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void mainMenu()
|
|
|
|
{
|
2015-10-01 13:38:24 -05:00
|
|
|
cout<<"\n\n***************"<<endl;
|
|
|
|
cout<<"** Main Menu **"<<endl;
|
|
|
|
cout<<"***************\n"<<endl;
|
|
|
|
cout<<"\n6. Your account"<<endl;
|
|
|
|
cout<<"3. Boards"<<endl;
|
|
|
|
cout<<"2. Messages"<<endl;
|
|
|
|
cout<<"1. Groups\n"<<endl;
|
|
|
|
cout<<"8. Logout\n"<<endl;
|
|
|
|
cout<<"Enter choice: ";
|
|
|
|
}
|
|
|
|
|
2015-10-06 00:00:26 -05:00
|
|
|
bool verifyCredentials(string n, string p)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < users.size(); ++i)
|
|
|
|
{
|
|
|
|
if (users[i].getName() == n && users[i].getPassword() == p)
|
|
|
|
{
|
2015-10-06 12:19:01 -05:00
|
|
|
currentUser = users[i];
|
2015-10-06 00:00:26 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-01 13:38:24 -05:00
|
|
|
void loginMenu()
|
2015-10-06 00:00:26 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
string name;
|
|
|
|
string password;
|
|
|
|
|
|
|
|
//loginCredentials c(name,password);
|
|
|
|
|
|
|
|
cout<<"\n\n****************"<<endl;
|
|
|
|
cout<<"****** Login Menu **"<<endl;
|
|
|
|
cout<<"****************\n\n"<<endl;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
|
|
|
|
cout<<"\nUsername: "<<endl;
|
|
|
|
cin>>name;
|
|
|
|
cin.clear();
|
|
|
|
cin.ignore();
|
|
|
|
|
|
|
|
cout<<"\nPassword: "<<endl;
|
|
|
|
cin>>password;
|
|
|
|
cin.clear();
|
|
|
|
cin.ignore();
|
|
|
|
|
|
|
|
if (verifyCredentials(name,password))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cout<<"Invalid credentials!"<<endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mainMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void startMenu()
|
2015-10-01 13:38:24 -05:00
|
|
|
{
|
|
|
|
cout<<"\n\n** Enter BBS **"<<endl;
|
|
|
|
cout<<"0. Login"<<endl;
|
|
|
|
cout<<"7. Request new account\n\n";
|
|
|
|
cout<<"-1. Exit\n\n"<<endl;
|
|
|
|
cout<<"Enter choice: ";
|
2015-09-29 22:49:18 -05:00
|
|
|
}
|
|
|
|
|
2015-10-06 12:19:01 -05:00
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
mainMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
void editAccountMenu()
|
|
|
|
{
|
|
|
|
cout<<"*********************************"<<endl;
|
|
|
|
cout<<"Edit Account"<<endl;
|
|
|
|
cout<<"*********************************\n"<<endl;
|
|
|
|
|
|
|
|
cout<<"0. Change Username"<<endl;
|
|
|
|
cout<<"1. Change Password"<<endl;
|
|
|
|
cout<<"2. Change Phone Number"<<endl;
|
|
|
|
cout<<"3. Change Fax Number"<<endl;
|
|
|
|
cout<<"4. Change Postal Number"<<endl;
|
|
|
|
cout<<"5. Back to Main Menu"<<endl;
|
|
|
|
cout<<"\n\nEnter choice:";
|
|
|
|
|
|
|
|
int choice;
|
|
|
|
cin >> choice;
|
|
|
|
switch(choice)
|
|
|
|
{
|
|
|
|
case 0: changeUsername(); break;
|
|
|
|
case 1: changePassword(); break;
|
|
|
|
case 2: changePhone(); break;
|
|
|
|
case 3: changeFax(); break;
|
|
|
|
case 4: changePostal(); break;
|
|
|
|
case 5: mainMenu(); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void yourAccount()
|
|
|
|
{
|
|
|
|
cout<<"*********************************"<<endl;
|
|
|
|
cout<<"Your Account"<<endl;
|
|
|
|
cout<<"*********************************\n"<<endl;
|
|
|
|
cout<<"\nName: "<< currentUser.getName() <<endl;
|
|
|
|
cout<<"\nPassword: "<< currentUser.getPassword() <<endl;
|
|
|
|
cout<<"\nPhone: "<< currentUser.getPhoneNumber() <<endl;
|
|
|
|
cout<<"\nFax: "<< currentUser.getFaxNumber() <<endl;
|
|
|
|
cout<<"\nPostal: "<< currentUser.getPostalAddress() <<endl;
|
|
|
|
cout<<"\n1.Edit Account"<<endl;
|
|
|
|
cout<<"\n0. Return to main menu"<<endl;
|
|
|
|
cout<<"\n\nEnter choice:";
|
|
|
|
|
|
|
|
int choice;
|
|
|
|
cin >> choice;
|
|
|
|
switch(choice)
|
|
|
|
{
|
|
|
|
case 0: mainMenu(); break;
|
|
|
|
case 1: editAccountMenu(); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void showMessages()
|
|
|
|
{
|
|
|
|
//Causing seg fault
|
|
|
|
// Relation temp = engine.getTableFromName("Messages");
|
|
|
|
//temp.display();
|
|
|
|
cout<<"\n\n0. Return to main menu"<<endl;
|
|
|
|
cout<<"\n\nEnter choice:";
|
|
|
|
|
|
|
|
int choice;
|
|
|
|
cin >> choice;
|
|
|
|
switch(choice)
|
|
|
|
{
|
|
|
|
case 0: mainMenu(); break;
|
|
|
|
}
|
|
|
|
}
|
2015-09-29 22:49:18 -05:00
|
|
|
|
2015-10-01 13:38:24 -05:00
|
|
|
void eventHandler(int choice)
|
|
|
|
{
|
|
|
|
switch(choice)
|
|
|
|
{
|
2015-10-06 00:00:26 -05:00
|
|
|
case 0: loginMenu(); break;
|
2015-10-01 13:38:24 -05:00
|
|
|
case 1: showGroups(); break;
|
|
|
|
case 2: showMessages(); break;
|
|
|
|
case 3: boardMenu(); break;
|
|
|
|
case 4: boardList(); break;
|
|
|
|
case 5: goToBoard(); break;
|
|
|
|
case 6: yourAccount(); break;
|
|
|
|
case 7: newAccount(); break;
|
2015-10-06 00:00:26 -05:00
|
|
|
case 8: startMenu(); break;
|
2015-10-01 13:38:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-09-29 22:49:18 -05:00
|
|
|
int main()
|
|
|
|
{
|
2015-10-06 12:19:01 -05:00
|
|
|
|
|
|
|
//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 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);
|
2015-10-06 00:00:26 -05:00
|
|
|
users.push_back(u0);
|
|
|
|
users.push_back(u1);
|
|
|
|
users.push_back(u2);
|
|
|
|
users.push_back(u3);
|
|
|
|
users.push_back(u4);
|
|
|
|
|
2015-10-06 12:19:01 -05:00
|
|
|
Message m0("JOHN_CENA", "Duke", "10/6/2015", "Who's champ?");
|
|
|
|
Message m1("Taggert", "Caleb", "12/24/1997", "I'm faster");
|
|
|
|
Message m2("Caleb", "Lo Wang", "4/13/1998", "Extra crispy");
|
|
|
|
mesages.push_back(m0);
|
|
|
|
mesages.push_back(m1);
|
|
|
|
mesages.push_back(m2);
|
|
|
|
|
|
|
|
//User Relation & Attributes
|
|
|
|
Attribute userAt1("Name", "VARCHAR(20)", true);
|
|
|
|
Attribute userAt2("Phone Number", "VARCHAR(20)", false);
|
|
|
|
Attribute userAt3("Fax Number", "VARCHAR(20)", false);
|
|
|
|
Attribute userAt4("Postal Address", "VARCHAR(20)", false);
|
|
|
|
vector<Attribute> userAttributes;
|
|
|
|
userAttributes.push_back(userAt1);
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
//Message Relation & Attributes
|
|
|
|
Attribute messageAt1("Sender", "VARCHAR(20)", true);
|
|
|
|
Attribute messageAt2("Receiver", "VARCHAR(20)", false);
|
|
|
|
Attribute messageAt3("Time Stamp", "VARCHAR(20)", false);
|
|
|
|
Attribute messageAt4("Text", "VARCHAR(20)", false);
|
|
|
|
vector<Attribute> messageAttributes;
|
|
|
|
messageAttributes.push_back(messageAt1);
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
//Board Relation & Attributes
|
|
|
|
Attribute boardAt1("Name", "VARCHAR(20)", true);
|
|
|
|
Attribute boardAt2("Description", "VARCHAR(20)", false);
|
|
|
|
Attribute boardAt3("Group", "VARCHAR(20)", false);
|
|
|
|
vector<Attribute> boardAttributes;
|
|
|
|
boardAttributes.push_back(boardAt1);
|
|
|
|
boardAttributes.push_back(boardAt2);
|
|
|
|
boardAttributes.push_back(boardAt3);
|
|
|
|
Relation boardRelation("Board Relation", boardAttributes);
|
|
|
|
|
|
|
|
//Group Relation & Attributes
|
|
|
|
Attribute groupAt1("Name", "VARCHAR(20)", true);
|
|
|
|
Attribute groupAt2("Description", "VARCHAR(20)", false);
|
|
|
|
vector<Attribute> groupAttributes;
|
|
|
|
groupAttributes.push_back(groupAt1);
|
|
|
|
groupAttributes.push_back(groupAt2);
|
|
|
|
Relation groupRelation("Group Relation", groupAttributes);
|
|
|
|
|
|
|
|
//Article Relation & Attributes
|
|
|
|
Attribute articleAt1("Author", "VARCHAR(20)", true);
|
|
|
|
Attribute articleAt2("Time Stamp", "VARCHAR(20)", false);
|
|
|
|
Attribute articleAt3("Length", "VARCHAR(20)", false);
|
|
|
|
vector<Attribute> articleAttributes;
|
|
|
|
articleAttributes.push_back(articleAt1);
|
|
|
|
articleAttributes.push_back(articleAt2);
|
|
|
|
articleAttributes.push_back(articleAt3);
|
|
|
|
Relation articleRelation("Article Relation", articleAttributes);
|
2015-10-06 00:00:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-09-29 22:49:18 -05:00
|
|
|
cout<<"***************************************"<<endl;
|
|
|
|
cout<<"Welcome to our BBS "<<endl;
|
|
|
|
cout<<"***************************************"<<endl;
|
|
|
|
|
2015-10-01 13:38:24 -05:00
|
|
|
eventHandler(8);
|
|
|
|
|
2015-09-29 22:49:18 -05:00
|
|
|
int choice;
|
|
|
|
|
|
|
|
|
2015-10-01 13:38:24 -05:00
|
|
|
while (choice != -1)
|
|
|
|
{
|
|
|
|
cin>>choice;
|
|
|
|
eventHandler(choice);
|
|
|
|
}
|
2015-09-29 22:49:18 -05:00
|
|
|
}
|
2015-10-06 00:00:26 -05:00
|
|
|
|