Update DBAppV2.cpp

This commit is contained in:
William Bracho Blok 2015-10-06 00:00:26 -05:00
parent 4515a7073b
commit 1dd7571292

View file

@ -1,8 +1,24 @@
#include <iostream>
//#include <iostream>
#include "User.h"
using namespace std;
/*
vector<User> users;
// struct loginCredentials
// {
// string name;
// string password;
// loginCredentials(string n, string p)
// {
// name = n;
// password = p;
// }
// };
void yourAccount()
{
cout<<"*********************************"<<endl;
@ -70,12 +86,48 @@ void showGroups()
}
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;
}
}
void newAccount()
{
cout<<"*********************************"<<endl;
cout<<"Request new account"<<endl;
cout<<"*********************************\n"<<endl;
cout<<"\n\nNew account generated"<<endl;
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;
cout<<"\n8. Return to login menu"<<endl;
cout<<"\n\nEnter choice:";
@ -96,7 +148,63 @@ void mainMenu()
cout<<"Enter choice: ";
}
bool verifyCredentials(string n, string p)
{
for(int i = 0; i < users.size(); ++i)
{
if (users[i].getName() == n && users[i].getPassword() == p)
{
return true;
}
}
}
void loginMenu()
{
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()
{
cout<<"\n\n** Enter BBS **"<<endl;
cout<<"0. Login"<<endl;
@ -110,7 +218,7 @@ void eventHandler(int choice)
{
switch(choice)
{
case 0: mainMenu(); break;
case 0: loginMenu(); break;
case 1: showGroups(); break;
case 2: showMessages(); break;
case 3: boardMenu(); break;
@ -118,13 +226,35 @@ void eventHandler(int choice)
case 5: goToBoard(); break;
case 6: yourAccount(); break;
case 7: newAccount(); break;
case 8: loginMenu(); break;
case 8: startMenu(); break;
}
};
int main()
{
//needs to load all the relations - at least the user relation
User u0("JOHN_CENA", "UberWrestling", "111-222-3333", "444-555-6666", "77432", true);
User u1("user1", "gig'em!", "111-222-3333", "444-555-6666", "77432", false);
User u2("user1", "gig'em!", "111-222-3333", "444-555-6666", "77432", false);
User u3("user2", "gig'em!", "111-222-3333", "444-555-6666", "77432", false);
User u4("user3", "gig'em!", "111-222-3333", "444-555-6666", "77432", false);
users.push_back(u0);
users.push_back(u1);
users.push_back(u2);
users.push_back(u3);
users.push_back(u4);
DBEngine v8;
cout<<"***************************************"<<endl;
cout<<"Welcome to our BBS "<<endl;
cout<<"***************************************"<<endl;
@ -140,4 +270,4 @@ int main()
eventHandler(choice);
}
}
*/