Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void register_user(vector<Users*> &User,Users& current_user){
- int redo;
- string name;
- do{
- redo=0;
- cout << "username: ";
- getline (cin, name);
- for(int i=0;i<User.size();i++){
- if(name.compare(User[i]->ID.username) == 0){
- cout << "This name already exists please type a different name!" << endl;
- redo = 1;
- }
- if(name.compare("\n") == 0 || name.compare("guest:guest")==0){
- cout << "forbidden name,please type a different name" << endl;
- redo=1;
- }
- }
- }while(redo);
- //
- User.push_back(new Punter);
- int i = User.size()-1;
- User[i]->ID.user_id = i+1;
- User[i]->ID.username.assign(name);
- User[i]->ID.fullname.assign(name); // this could be changed later in the account settings
- User[i]->ID.type = 1;
- User[i]->ID.status.assign("A");
- User[i]->ID.balance = 0.0;
- User[i]->ID.freebets.push_back(0.0); //
- do{
- redo=0;
- cout << "password: ";
- string pass1;
- getline (cin,pass1);
- cout << "Please retype your password:" ;
- string pass2;
- getline (cin,pass2);
- if (pass1.compare(pass2) != 0){
- cout << "You should insert the same password twice" << endl;
- redo=1;
- }
- else{
- User[i]->ID.password.assign(pass1);
- }
- }while(redo);
- write_users(User); //arxeio susthmatos save
- current_user = *User[i];
- User[i]->exprint();
- }
- void login_user(vector<Users*> &User,Users& current_user){
- cout << "Welcome to KAPPA BET!" << endl;
- cout << "Please type username and password to login to your account!" << endl;
- cout << "If you don't have an account ,press (Enter) or type guest:guest to login as guest" << endl;
- int anagnwr=-1;
- int guest=0;
- int redo;
- do{
- redo=0;
- cout << "username: " ;
- string name;
- string rightpass;
- getline(cin,name);
- if((name.compare("guest:guest") == 0) || name.compare("\n")){
- guest = 1;
- break;
- }
- for(int i=0;i<User.size();i++){
- if(name.compare(User[i]->ID.username) == 0){
- rightpass.assign(User[i]->ID.password);
- anagnwr=i;
- }
- }
- string provpass;
- cout << "password: ";
- getline(cin,provpass);
- if(provpass.compare(rightpass) == 0){
- redo=0;
- }
- else{
- cout << "Wrong Credentials! Please Retry!" << endl;
- redo=1;
- }
- }while(redo);
- if(guest == 0){
- char locked = 'L';
- if(locked == User[anagnwr]->ID.status[0]){
- cout << "Your account has been locked due to: ";
- for(int i=2;User[anagnwr]->ID.status[i] != '\n';i++){
- cout << User[anagnwr]->ID.status[i];
- }
- exit(1);
- }
- }
- //eisodos xrhsth sto arxiko menu analoga me to user.type h an einai guest
- if(guest == 1){
- Users* temp = new Guest();
- //gurnaw
- current_user = *temp;
- temp->exprint();
- }
- else{
- current_user = *User[anagnwr];
- User[anagnwr]->exprint();
- }
- write_users(User);
- }
- int main(int argc, char** argv) {
- vector<Users*> User;
- vector<History*> history;
- vector<Bethistory*> bethistory;
- read_users(User);
- Users currentUser;
- if (argc == 1){
- //xwris parameters
- login_user(User,currentUser);
- }
- else if(argc == 2){
- //mia parametros
- string parameter(argv[1]);
- capitalize(¶meter);
- if(strcmp(parameter.c_str(),"-r") == 0){
- //register a user
- register_user(User,currentUser);
- }
- }
- //management input
- bethistoryfun(bethistory,10,1,"1.1.2.3",10.5,'W');
- write_bet(bethistory);
- */
- write_users(User);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement