Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- string name;
- int choice;
- int id = 0;
- readFile();
- // Log in validation
- while (id <= 0)
- {
- id = logIn();
- }
- //name = "<Name>";
- name = userID[id].getFirstname();
- cout << "Welcome, " << name << "!\n";
- do{
- choice = mainMenu();
- switch(choice)
- {
- case 1: // view friends
- viewFriends(id);
- break;
- case 2: // search for new friends
- searchNewFriends();
- break;
- case 3: // friends rec
- friendRecs();
- break;
- case 4: // quit
- {
- cout << " You are signed out"
- << "\n\t- GOODBYE! -" << endl;
- }
- }
- }while(choice != 4);
- return 0;
- }
- /// Returns bool for whether or not username & password combo are matched
- int logIn()
- {
- string un, pw, fn, ln, city, state;
- int choice = 0;
- int id;
- bool option = false;
- while (!option)
- {
- while (choice != 1 && choice != 2 && choice != 3)
- {
- cout << "\t- WELCOME TO SPONGEBOOK -" << endl;
- cout << "1. Log in " << endl;
- cout << "2. Create an account " << endl;
- cout << "3. Quit " << endl;
- cout << "\nEnter choice: ";
- cin >> choice;
- cout << endl;
- }
- if (choice == 1)
- {
- int count = 0;
- while (true)
- {
- string userInput;
- cout << "\t- LOG IN -" << endl
- << "Username: ";
- cin >> un;
- cout << "Password: ";
- cin >> pw;
- for (int i = 1; i <= userID.size(); i++)
- {
- if (un == userID[i].getUsername() && pw == userID[i].getPassword())
- {
- cout << "\n\t*** Login successful ***\n" << endl;
- id = i;
- option = true;
- return id;
- }
- }
- cout << "\n\t*** Incorrect username or password. Please try again **" << endl;
- count ++;
- if (count > 3)
- {
- while (userInput != "YES" && userInput != "NO")
- {
- cout << "\nMultiple failed attempts. Would you like to go back to the main menu? ";
- cin >> userInput;
- transform(userInput.begin(), userInput.end(), userInput.begin(),::toupper);
- }
- if (userInput == "YES")
- {
- cout << endl;
- choice = 0;
- option = true;
- return false;
- }
- else if (userInput == "NO")
- {
- choice = 1;
- count = 0;
- }
- }
- }
- }
- else if (choice == 2)
- {
- cout << "\t- CREATE AN ACCOUNT -" << endl
- << "First name: ";
- cin >> fn;
- cout << "Last name: ";
- cin >> ln;
- cout << "Username: ";
- cin >> un;
- cout << "Password: ";
- cin >> pw;
- cout << "City: ";
- cin.ignore();
- getline(cin, city);
- cout << "State: ";
- cin >> ws;
- cin >> state;
- id = userID.size() + 1;
- User newUser(fn, ln, un, pw, city, state, id);
- userID.push_back(newUser);
- cout << "\n\t*** Account successfully created. You may now log in ***\n" << endl;
- choice = 0;
- }
- else if (choice == 3)
- {
- cout << "\t- GOODBYE! -" << endl;
- exit(0);
- }
- }
- return id;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement