fix sesion never end and implement create user funcionality

This commit is contained in:
2020-05-21 20:57:18 +02:00
parent b8831c9e35
commit 2783e385a4
6 changed files with 29 additions and 3 deletions

View File

@@ -31,7 +31,7 @@ bool session_manager::validate_pass(){
void session_manager::start_dialog(){
char* buffer = new char[5];
while(true){
this->read_data(buffer,5);
int n_read=this->read_data(buffer,5);
if(strcmp(buffer, "exec")==0){
this->execute();
}else if(strcmp(buffer, "info")==0){
@@ -40,7 +40,9 @@ void session_manager::start_dialog(){
this->remove();
}else if(strcmp(buffer,"uinf")==0){
this->send_user_info();
}else if(strcmp(buffer,"exit")==0){
}else if(strcmp(buffer,"cusr")==0){
this->create_user();
}else if((strcmp(buffer,"exit")==0)||(n_read==0)){
break;
}
}
@@ -129,6 +131,19 @@ void session_manager::send_user_info(){
this->write_data("end:info");
}
void session_manager::create_user(){
char* user=new char[256];
char* pass=new char[256];
char* admin=new char[256];
this->read_data(user, 256);
this->read_data(pass, 256);
this->read_data(admin, 256);
this->data->create_user(std::string(user), std::string(pass), admin[0]=='t');
delete [] (user);
delete [] (pass);
delete [] (admin);
}
int session_manager::read_data(char* input, int size){
return read(this->fd, input, size);
}