예제 #1
0
파일: server.c 프로젝트: mannias/SO
void loginUser(Message* msg){
	int finished = 0;
	char* data = msg->body;
	node* aux = users->head;
	char* tokens;
	if((tokens = strtok(data,",")) == NULL){
		addMessageClient(msg->referer, fillMessageData("login", "error", "Bad Format"));
		return;
	}
	user* elem;
	if((elem = findUserByUsername(tokens)) != NULL){
		if((tokens = strtok(NULL,",")) == NULL){
			addMessageClient(msg->referer, fillMessageData("login", "error", "Bad Format"));
			return;
		}
		if(strcmp(elem->password, tokens) == 0){
			printf("User %s logued correctly\n", elem->username);
			addMessageClient(msg->referer, fillMessageData("login", "success", elem->username));
		}else{
			printf("Incorrect password, User: %s\n", elem->username);
			addMessageClient(msg->referer, fillMessageData("login", "error", "Incorrect Password"));
		}
	}else{
		printf("Incorrect Username\n");
		addMessageClient(msg->referer, fillMessageData("login", "error", "Incorrect Username"));
	}
	printf("salio\n");
}
예제 #2
0
파일: server.c 프로젝트: mannias/SO
void sendUserFee(Message* msg){
	char* num;
	user* data = findUserByUsername(msg->body);
	sprintf(num, "%f", data->fee);
	printf("Sending %s fee\n", data->username);
	addMessageClient(msg->referer, fillMessageData("user", "fee", (char*)num));
}
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;}
}
예제 #4
0
User *login(int sd, SOCKADDR *c, int cLen, User *head, char *ipAddr)
{
    char username[MAX_NAME_LEN];
    char password[MAX_NAME_LEN];
    User *user;
	int i;

    // Prompt for user name
    sendEncrypt(sd, "\nUsername: "******"\nPassword: ", BUFFER_SIZE, 0, c, cLen);
    sendDone(sd, c, cLen);
    recvDecrypt(sd, password, MAX_NAME_LEN, c, &cLen);

    // Search for the given username
    user = findUserByUsername(head, username);

	//Crypt(password, MAX_NAME_LEN, 0);

    // If found and password matches, return user type
    if (user && !strcmp(user->password, password))
	{
		// Get IP address
		strcpy(user->ipAddr, ipAddr);
        return user;
	}

    return NULL;
}
예제 #5
0
파일: server.c 프로젝트: mannias/SO
void sendEmails(Message* msg){
	user* elem = findUserByUsername(msg->body);
	char* num;
	if(elem->mail_list == NULL){
		addMessageClient(msg->referer, fillMessageData("mail", "receive", "0"));
	}else{
		sprintf(num,"%d",elem->mail_list->length);
		addMessageClient(msg->referer, fillMessageData("mail", "receive", (char*)num));
		addMailList(msg->referer, elem->mail_list);
	}
}
예제 #6
0
파일: server.c 프로젝트: mannias/SO
void clientReciveMails(Message* msg, int id){
	sendData(msg->referer, fillMessageData("mail", "continue", ""), sizeof(Message));
	mail* info = (mail*)listenMessage(msg->referer, sizeof(mail));
	if(info != NULL){
		pthread_mutex_lock(&mut);
		if(findUserByUsername(info->to) != NULL){
			pushMail(info);
			sendData(msg->referer, fillMessageData("mail", "success", "Mail Sent Correctly\n"), sizeof(Message));
			pthread_cond_signal(&newMail);
		}else{
			sendData(msg->referer, fillMessageData("mail", "error", "Wrong Username\n"), sizeof(Message));
		}
		pthread_mutex_unlock(&mut);
	}
}
예제 #7
0
//sends a single user record to the file appending to the existing contents
void USR_Manager::sendToFile(Util::User user) {
    
    std::ofstream output;
    output.open(Util::usersFilePath(), std::ofstream::out | std::ofstream::app);
    
    //check if saved user.highestscore is greater than the current highestscore score.
    if (checkIfUserExists(user))
    {
        int highscore_from_file = findUserByUsername(user.username).highestScore;
        
        if (user.highestScore > highscore_from_file)
            output << user.username + " - " + std::to_string(user.highestScore) + "\n";
    }
    else
    {
        output << user.username + " - " + std::to_string(user.highestScore) + "\n";
    }
    
    output.close();
}
예제 #8
0
파일: server.c 프로젝트: mannias/SO
static void *
reciveMails(void* arg){
	mail* info;
	int status = 0;
	user* data;
	while(1){
		pthread_mutex_lock(&mut);
		info = popMail();
		if(info != NULL){
			data = findUserByUsername(info->to);
			if(data == NULL){
				printf("Wrong Username\n");
			}else{
				printf("Recieved email from %s\n", info->from);
				addNode(data->mail_list, info, true);
				if(info->attachments[0] != '0'){
					FILE *fp = fopen(info->attachments, "r");
					if (fp == NULL) {
						data->fee +=1;
						printf("While opening file %s.\n", info->attachments);
						perror("File open error");
					}else{
						struct stat st;
						stat(info->attachments, &st);
						int filesize = st.st_size;
						data->fee += filesize;
					}
				}else{
					data->fee +=1; 
				}
			}
		}else{
			printf("Mails Queue Empty, Sleeping\n");
			pthread_cond_wait(&newMail, &mut);
			printf("Woke Up to Consume Mail List\n");
		}
		pthread_mutex_unlock(&mut);
	}
}
예제 #9
0
//Boolean value returned if a user exists. 
bool USR_Manager::checkIfUserExists(Util::User user) {
    return findUserByUsername(user.username).username.compare(user.username) == 0;
}
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;}
}
예제 #11
0
int addNewCustomer(int sd, SOCKADDR *c, int cLen, User **head)
{
    char buffer[BUFFER_SIZE];
    char newP1[MAX_NAME_LEN], newP2[MAX_NAME_LEN];
    User *newCustomer = (User *)malloc(sizeof(User));
    float deposit;
    int pAttempts = 0;
    int uniqueUsername = 0;


    if (!newCustomer)
    {
        sendEncrypt(sd, "\n\nMemory error encountered. Returning to main menu.", BUFFER_SIZE, 0, c, cLen);
		sendEncrypt(sd, BORDER, BUFFER_SIZE, 0, c, cLen);
        return 0;
    }

    // Initialize
    *newCustomer = ZERO_USER;
    
	// Dislpay selection
	sendEncrypt(sd, BORDER, BUFFER_SIZE, 0, c, cLen);
	sendEncrypt(sd, "\nYou selected option '3 - Add a new customer to the system.'\n\n", BUFFER_SIZE, 0, c, cLen);
    
    // Prompt for new user's info
    sendEncrypt(sd, "Please enter the following information for the new user\n", BUFFER_SIZE, 0, c, cLen);
    sendEncrypt(sd, "\nFirst Name: ", BUFFER_SIZE, 0, c, cLen);
    sendDone(sd, c, cLen);
    RECV_DECRYPT(sd, newCustomer->firstName, MAX_NAME_LEN, c, &cLen);

    sendEncrypt(sd, "\nLast Name: ", BUFFER_SIZE, 0, c, cLen);
    sendDone(sd, c, cLen);
    RECV_DECRYPT(sd, newCustomer->lastName, MAX_NAME_LEN, c, &cLen);

    do
    {
        sendEncrypt(sd, "\nUsername: "******"\nThe username entered already exists. Please choose another name.\n", BUFFER_SIZE, 0, c, cLen);
    } while (!uniqueUsername);

    do
    {
	    sendEncrypt(sd, "\nPassword: "******"\nRe-enter Password: "******"\n\nThe passwords you entered do not match.\n\n", BUFFER_SIZE, 0, c, cLen);

        ++pAttempts;

    } while (pAttempts < 3); // Verify new password

    if (pAttempts == 3)
    {
        sendEncrypt(sd, "Returning to the main menu.", BUFFER_SIZE, 0, c, cLen);
        sendEncrypt(sd, BORDER, BUFFER_SIZE, 0, c, cLen);
        free(newCustomer);
        return 0;
    }

    sendEncrypt(sd, "\nInitial deposit: $", BUFFER_SIZE, 0, c, cLen);
    sendDone(sd, c, cLen);
    RECV_DECRYPT(sd, buffer, MAX_NAME_LEN, c, &cLen);
    sscanf(buffer, "%f", &deposit);
    newCustomer->balance = (unsigned int)(deposit*100);

    // Generate a random account number
    srand((unsigned)time(NULL));
    newCustomer->acctNum = 100000 + rand() / (RAND_MAX / (999998 - 100000 + 1) + 1);

    // Just in case by some strange bad luck, the acctnum exists, keep trying
    while (findUserByAcctNum(*head, newCustomer->acctNum))
        newCustomer->acctNum = 100000 + rand() / (RAND_MAX / (999998 - 100000 + 1) + 1);

    // Set type to Customer
    newCustomer->userType = 'C';

    // Add new user to list
    newCustomer->next = *head;
    *head = newCustomer;

    // Notify manager that new customer has been added
    sendEncrypt(sd, "\nThe new user has been added with the following information:\n\n", BUFFER_SIZE, 0, c, cLen);
    sprintf(buffer, "Name: %s %s\n", newCustomer->firstName, newCustomer->lastName);
    sendEncrypt(sd, buffer, BUFFER_SIZE, 0, c, cLen);

    sprintf(buffer, "Username: %s\n", newCustomer->username);
    sendEncrypt(sd, buffer, BUFFER_SIZE, 0, c, cLen);

    sprintf(buffer, "Account Number: %d\n", newCustomer->acctNum);
    sendEncrypt(sd, buffer, BUFFER_SIZE, 0, c, cLen);

    return 0;
}