int main() { UserNetwork network = UserNetwork(); //vector<User> users; /*User user; int random; typedef std::minstd_rand G; G g; typedef std::uniform_int_distribution<> D; D d(0, 9999); for(int i = 0; i < 10000; i++) { user = User(to_string(i),"a",to_string(i),"MB"); user.addPost(WallPost(to_string(i + 100), to_string(i))); user.addPost(WallPost(to_string(i + 99), to_string(i))); user.addPost(WallPost(to_string(i + 500), to_string(i))); user.addPost(WallPost(to_string(i + 1000), to_string(i))); network.addUser(user); users.insert(users.begin(), user); } for (auto iter = users.begin(); iter != users.end(); ++iter) { for (int j = 0; j < 100; j++) { random = d(g); cout << random << endl; iter->sendFriendRequest(to_string(random) , &network); } } for (auto iter = users.begin(); iter != users.end(); ++iter) { for (auto request = iter->getFriendRequests().begin(); request != iter->getFriendRequests().end(); ++request) { random = d(g); cout << random << endl; iter->acceptFriendRequest(*request, &network); } } */ network.readFromFile(); for (auto iter = network.getUsers()->begin(); iter != network.getUsers()->end(); ++iter) { //iter->setFriendRequestPointers(); bool going = true; while(going) {// = iter->getFriendRequests().begin(); request != iter->getFriendRequests().end(); ++request) { cout << iter->toString() << endl; try { iter->acceptFriendRequest(iter->getFriendRequests().at(0), &network); } catch(std::out_of_range& e) { going = false; } cout << iter->toString() << endl; } } network.toFile(); return 0; }
void userLogin() { string username, password; if (!loginStatus) { cout << "Login to existing account" << endl; cout << "Enter username: "******"Enter password for " << username << ": "; cin >> password; if (usernetwork.checkPassword(username, password)) { cout << "Login successful. " << endl; loginStatus = true; uname = username; curr_user = usernetwork.getUser(username); return; } else { cout << "Login unsuccessful. " << endl; return; } }
int main(int argc, char** argv) { if (argc < 2) { cout << "Usage:./run datafile." << endl; return -1; } UserNetwork * network = new UserNetwork; network->CreateUsersFromFile(string(argv[1])); int option; string uname, pass, pass1, pass2, rname, bday; string input = ""; User *user = NULL; while (true) { cout << endl << endl << endl << "What do you want to do?" << endl; cout << "Option 1: Create a new user." << endl; cout << "Option 2: Log in." << endl; cout << "Option 3: Quit." << endl; cout << "Please input your selection: " << endl; if (!ReadInt(option) || option > 3 || option < 1) { cout << "Invalid option, please input again: " << endl; continue; } switch (option) { case 1: cout << "Create a new user: "******"Please input your username: "******"Username already exists. Re-enter: " << endl; getline(cin, uname); } while (true){ cout << "Set your password: "******"Confirm your password: "******"Passwords don't match. Re-enter. " << endl; continue; } break; } cout << "Enter your realname: " << endl; getline(cin, rname); cout << "Enter your birthday [MM/DD/YYYY] : " << endl; getline(cin, bday); network->AddUser(uname, pass1, rname, bday); cout << "User " << uname << " added" << endl << endl; break; case 2: cout << "Enter username: "******"Username doesn't exist. Re-enter: " << endl; getline(cin, uname); } while (true){ cout << "Enter your password: "******"Wrong password. Re-enter. " << endl; continue; } break; } menu(user); break; case 3: network->WriteUsersToFile(string(argv[1])); return 0; } } }
int main(int argc, const char * argv[]) { // make a usernetworklist UserNetwork test; string username = ""; test.addUser("krishna", "sup", "Krishna Ling", "S"); test.addUser("vince", "hi", "Vince Gan", "Be"); test.addUser("vince2", "hi2", "Vince Gan2", "Be2"); test.addUser("vince3", "hi3", "Vince Gan3", "Be3"); test.addUser("vince4", "hi4", "Vince Gan4", "Be4"); test.WriteToFileUserList(); test.readFromFile("./userList.txt"); //cout << test.returnUser("krishna").userInfoString(); //cout << test.returnUser("vince").userInfoString(); test.sendRequest("vince", "krishna"); test.sendRequest("vince", "vince2"); test.sendRequest("vince", "vince3"); test.sendRequest("vince", "vince4"); test.acceptRequest("krishna", "vince"); test.acceptRequest("vince2", "vince"); test.acceptRequest("vince3", "vince"); test.acceptRequest("vince4", "vince"); cout << test.returnUser("vince").printFriendsList() << endl; // int counter; // if counter = 1 then password exists // string yourpass; // cout << "Enter Password: "******"Password exists" << endl; // return 0; // } // itr++; // } // // // if(counter !=1){ // cout << "Password does not exist"<< endl; // } return 0; }
int main() { /*std::ifstream myfile; myfile.open("users.txt"); //default modes: ios::in and ios::out for input and output std::string user; */ curr_user = nullptr; usernetwork.readFromFile(); cout << "User Network read from file. " << endl; char choice; // command entered by user do { (loginStatus) ? print_login_menu(uname) : print_menu(); choice = toupper(get_command()); switch (choice) { //basic functions case 'C': //create new user createUser(); break; case 'L': //login if (!loginStatus) userLogin(); else loginStatus = false; break; case 'Q': break; case 'A': if (loginStatus) { addFriend(); break; } case 'D': //display wall if (loginStatus) { displayWall(uname); break; } case 'N': //create new post on wall if (loginStatus) { createNewPost(uname); break; } case 'E': // enter my wall if (loginStatus) { enterPost(curr_user); break; } //debug functions case 'P': //print all users show_network(usernetwork); break; case 'F': // Display my friend if (loginStatus) { displayAllFriend(); break; } case 'I': // Enter my friend's wall if (loginStatus) { enterFriendWall(); break; } case 'R': // Get the Route of other user if (loginStatus) { getTheRoute(); break; } case 'S': // Find my possible friend if (loginStatus) { getpossibleFriend(); break; } default: cout << choice << " is invalid." << endl; } } while (choice != 'Q'); usernetwork.writeToFile(); return 0; }
void createUser() { string username, firstname, lastname, password; int date[3] = { 0, 0, 0 };//day, month, year; cout << "Creating new user account" << endl; cout << "Enter desired username: "******"Username taken." << endl; else { cout << "Please enter a password: "******"Please enter your first name: "; cin >> firstname; cout << "Please enter your last name: "; cin >> lastname; cout << "Enter your date of birth." << endl; cout << "Day: (dd) "; while (!(cin >> date[0]) || date[0] > 31 || date[0] < 1) { cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); cout << "Please input a valid day: " << endl; } cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); cout << "Month: (mm) "; while (!(cin >> date[1]) || date[1] > 12 || date[1] < 1) { cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); cout << "Please input a valid month: " << endl; } cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); cout << "Year: (yyyy) "; while (!(cin >> date[2]) || date[2] > 2015 || date[2] < 1900) { cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); cout << "Please input a valid year: " << endl; } cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); stringstream formatString; formatString << username << " " << password << " " << firstname << " " << lastname << " " << date[0] << " " << date[1] << " " << date[2]; User newUser(formatString.str()); // cout << formatString.str() << endl; usernetwork.addUser(newUser); //usernetwork.printUsers(); cout << "User has been added successfully." << endl; } }
void show_network(UserNetwork usernetwork) { usernetwork.printUsers(); }