int registerUser(char* user, int socket, struct registration* registrations, size_t* numReg) { struct registration* reg; reg = findUserByName(user,registrations, *numReg); if (reg != NULL) { return 403; } if (*numReg < MAX_REG) { registrations[*numReg].socketfd = socket; strncpy(registrations[*numReg].user, user, MAX_USERNAME_LEN); (*numReg)++; printf("Registered user (%s) on socket %i\n", user, socket); return 200; } return 403; }
void ListUsers::removeUser(const std::string &s1, const std::string &s2){ //brisanje korisnika User remove; try{if(s2=="") remove=findUserByUsername(s1); else remove=findUserByName(s1,s2); pop(remove);} catch(std::string a){std::cout <<"\033[1;31m"<< a << "\033[0m" << std::endl;} }
bool UserManage::createUser(std::string userName, std::string userPassword, std::string userEmail, std::string userPhone) { if (findUserByName(userName)) { return false; } else { User create(userName, userPassword, userEmail, userPhone); users_.push_back(create); return true; } }
void ListUsers::updateUser(const std::string &s1,const std::string &s2) //azuriranje korisnika { User update; try{if(s2=="") update=findUserByUsername(s1); else update=findUserByName(s1,s2); int choise; std::string stariUsername=update.getUserAcc().getUsername(); int a=1; while(a==1) { cout<<"\033[1;34m--- Options --- "<< std::endl; cout<<"\033[1;34m1. Enter 1 to change name and surname "<< std::endl; cout<<"\033[1;34m2. Enter 2 to change unique number of birth "<< std::endl; cout<<"\033[1;34m3. Enter 3 to change user account settings(username and password) \033[0m"<<std::endl; choise=enter_int(); if(choise==1) { std::string name; std::string surname; std::cout<<"\033[1;34mEnter a new name: \033[0m"; std::cin.ignore(); getline(std::cin,name); std::cout<<"\033[1;34mEnter a new surname: \033[0m"; getline(std::cin,surname); update.setPerson(name,surname); } else if(choise==2) { std::cout<<"\033[1;34mEnter a new unique number of birth: \033[0m"; std::string unob; cin.ignore(); getline(std::cin,unob); while(unob.size()!=13 || !check_string_all_digits(unob)) //provjerava validnost jmbg { std::cout << "\033[1;34mUnique number of birth must contain exactly 13 digits. Please enter it correctly: \033[0m"; getline(std::cin,unob); } update.setUnob(unob); } else if(choise==3) { std::string username; std::string password; std::cout<<"\033[1;34mEnter a new username: \033[0m"; // korisnicko ime mora biti jedinstveno cin.ignore(); while(getline(std::cin,username)) { while(check_string_for_spaces(username)) { std::cout << "\033[1;34mUsername can't contain blank spaces. Please enter a new one: \033[0m"; //provjerava prazna mjesta u usernameu getline(std::cin,username); } if(!findUserByUsernameBool(username)) { std::cout<<"\033[1;34mEnter a new password: \033[0m"; getline(std::cin,password); while(check_string_for_spaces(password) || password.size()<6) //provjera da li password ima prazno mjesto i da li je kraci od 6 karaktera { std::cout << "\033[1;34mPassword can't contain blank spaces and must have at least 6 characters. Please enter a new one: \033[0m"; getline(std::cin,password); } update.setAccount(username,password); break; } else std::cout<< "\033[1;34mUsername " << username << " is already taken by another user. Please enter a different one: \033[0m"; } } else { cout<<"\033[1;31mWrong input!\033[0m"<< std::endl; } std::cout<<"\033[1;34mIf you want more changes enter 1, otherwise enter 0: \033[0m"<< std::endl; //nakon sto se izvrsi neka promjena, nudi novu promjenu ili izlaz iz azuriranja int x; x=enter_int(); if(x!=1) a=0; } auto it=(*this).begin(); //azuriranje korisnika u listu korisnika while(it!=(*this).end()){ if((*it).getInfo().getUserAcc().getUsername()==stariUsername){ (*it).setInfo(update); break;} ++it; }} catch(std::string a){std::cout <<"\033[1;31m"<< a << "\033[0m" << std::endl;} }