Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.65 KB | None | 0 0
  1. void register_user(vector<Users*> &User,Users& current_user){
  2.     int redo;
  3.     string name;
  4.     do{
  5.         redo=0;
  6.         cout << "username: ";
  7.         getline (cin, name);
  8.         for(int i=0;i<User.size();i++){
  9.             if(name.compare(User[i]->ID.username) == 0){
  10.                 cout << "This name already exists please type a different name!" << endl;
  11.                 redo = 1;
  12.             }
  13.             if(name.compare("\n") == 0 || name.compare("guest:guest")==0){
  14.                 cout << "forbidden name,please type a different name" << endl;
  15.                 redo=1;
  16.             }
  17.         }
  18.     }while(redo);
  19. //
  20.     User.push_back(new Punter);
  21.     int i = User.size()-1;
  22.     User[i]->ID.user_id = i+1;
  23.     User[i]->ID.username.assign(name);
  24.     User[i]->ID.fullname.assign(name); // this could be changed later in the account settings
  25.     User[i]->ID.type = 1;
  26.     User[i]->ID.status.assign("A");
  27.     User[i]->ID.balance = 0.0;
  28.     User[i]->ID.freebets.push_back(0.0); //
  29.     do{
  30.         redo=0;
  31.         cout << "password: ";
  32.         string pass1;
  33.         getline (cin,pass1);
  34.         cout << "Please retype your password:" ;
  35.         string pass2;
  36.         getline (cin,pass2);
  37.         if (pass1.compare(pass2) != 0){
  38.             cout << "You should insert the same password twice" << endl;
  39.             redo=1;
  40.         }
  41.         else{
  42.             User[i]->ID.password.assign(pass1);
  43.         }
  44.     }while(redo);
  45.     write_users(User);  //arxeio susthmatos save
  46.     current_user = *User[i];
  47.     User[i]->exprint();
  48. }
  49.  
  50. void login_user(vector<Users*> &User,Users& current_user){
  51.     cout << "Welcome to KAPPA BET!" << endl;
  52.     cout << "Please type username and password to login to your account!" << endl;
  53.     cout << "If you don't have an account ,press (Enter) or type guest:guest to login as guest" << endl;
  54.     int anagnwr=-1;
  55.     int guest=0;
  56.     int redo;
  57.     do{
  58.         redo=0;
  59.         cout << "username: " ;
  60.         string name;
  61.         string rightpass;
  62.         getline(cin,name);
  63.         if((name.compare("guest:guest") == 0) || name.compare("\n")){
  64.             guest = 1;
  65.             break;
  66.         }
  67.         for(int i=0;i<User.size();i++){
  68.             if(name.compare(User[i]->ID.username) == 0){
  69.                 rightpass.assign(User[i]->ID.password);
  70.                 anagnwr=i;
  71.             }
  72.         }
  73.         string provpass;
  74.         cout << "password: ";
  75.         getline(cin,provpass);
  76.         if(provpass.compare(rightpass) == 0){
  77.             redo=0;
  78.         }
  79.         else{
  80.             cout << "Wrong Credentials! Please Retry!" << endl;
  81.             redo=1;
  82.         }
  83.     }while(redo);
  84.     if(guest == 0){
  85.         char locked = 'L';
  86.         if(locked == User[anagnwr]->ID.status[0]){
  87.             cout << "Your account has been locked due to: ";
  88.             for(int i=2;User[anagnwr]->ID.status[i] != '\n';i++){
  89.                 cout << User[anagnwr]->ID.status[i];
  90.             }
  91.             exit(1);
  92.         }  
  93.     }
  94.     //eisodos xrhsth sto arxiko menu analoga me to user.type h an einai guest
  95.     if(guest == 1){
  96.         Users* temp = new Guest();
  97.         //gurnaw
  98.         current_user = *temp;
  99.         temp->exprint();
  100.        
  101.     }
  102.     else{
  103.         current_user = *User[anagnwr];
  104.         User[anagnwr]->exprint();
  105.     }
  106.     write_users(User);
  107. }
  108.  
  109. int main(int argc, char** argv) {
  110.     vector<Users*> User;
  111.     vector<History*> history;
  112.     vector<Bethistory*> bethistory;
  113.     read_users(User);
  114.     Users currentUser;
  115.     if (argc == 1){
  116.         //xwris parameters
  117.         login_user(User,currentUser);
  118.     }
  119.     else if(argc == 2){
  120.         //mia parametros
  121.         string parameter(argv[1]);
  122.         capitalize(&parameter);
  123.         if(strcmp(parameter.c_str(),"-r") == 0){
  124.             //register a user
  125.             register_user(User,currentUser);
  126.         }
  127.     }
  128.     //management input
  129.  
  130.     bethistoryfun(bethistory,10,1,"1.1.2.3",10.5,'W');
  131.     write_bet(bethistory);
  132.     */
  133.    
  134.     write_users(User);    
  135.     return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement