Guest User

login.h

a guest
Mar 15th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.82 KB | None | 0 0
  1. #ifndef LOGING_H
  2. #define LOGIN_H
  3.  
  4. #include "feed.h"
  5.  
  6. #include <iostream>
  7. #include <vector>
  8.  
  9. using namespace std;
  10.  
  11. class LogInInfo {
  12.     vector<string> usernames;
  13.     vector<string> passwords;
  14.        
  15.     public:
  16.         void welcomePage() {
  17.            
  18.             int menuChoice;
  19.            
  20.             cout << "\nChirpy\n===========================\n"
  21.                  << "1) Log in\n2) Sign Up\n" << endl;
  22.                  
  23.             cin >> menuChoice;
  24.            
  25.             switch (menuChoice) {
  26.                 case 1: checkUser();
  27.                     break;
  28.                 case 2: createUser();
  29.                     break;
  30.                 default: cout << "Not an option\n";
  31.                          welcomePage();
  32.             }
  33.             welcomePage();
  34.         }
  35.    
  36.        
  37.         void createUser() {
  38.             string username, password;
  39.             int namePlace = 0;
  40.            
  41.             cout << "Enter new username:\n>> ";
  42.             cin >> username;
  43.            
  44.             for (int x = 0 ; x < usernames.size() ; x++) {
  45.                 if (username == usernames[x]) {
  46.                     cout << "That name is already taken\n" << endl;
  47.                     createUser();
  48.                 }
  49.                 namePlace = x;
  50.             }
  51.             usernames.push_back(username);
  52.            
  53.             cout << "\nWelcome " << usernames[namePlace] << endl;
  54.             cout << "Enter Password:\n>> ";
  55.             cin >> password;
  56.             passwords.push_back(password);
  57.             postToFeed();
  58.             welcomePage();
  59.         }
  60.        
  61.         void checkUser() {
  62.             string username, password;
  63.             int location;
  64.             cout << "Enter your username:\n>> ";
  65.             cin >> username;
  66.            
  67.             for (int x = 0 ; x < usernames.size() ; x++) {
  68.                 if (username == usernames[x]) {
  69.                     cout << "\nWelcome " << usernames[x] << endl;
  70.                     cout << "Enter your password:\n>> ";
  71.                     cin >> password;
  72.                    
  73.                     if (password == passwords[x]) {
  74.                         cout << "\nSucessfully Loged in\n" << endl;
  75.                         postToFeed();
  76.                     }
  77.                     else {
  78.                         cout << "\nPassword not found. Going back to menu.\n" << endl;
  79.                         welcomePage();
  80.                     }
  81.                 }
  82.                 else {
  83.                     cout << "\nUsername not found. Going back to menu.\n" << endl;
  84.                     welcomePage();
  85.                 }
  86.             }
  87.            
  88.         }
  89.        
  90.         void postToFeed() {
  91.             Myfeed *goToFeed = new Myfeed;
  92.            
  93.             goToFeed->mainMenu();
  94.            
  95.         }
  96.        
  97. };
  98.  
  99.  
  100. #endif
Add Comment
Please, Sign In to add comment