fix sesion never end and implement create user funcionality
This commit is contained in:
parent
b8831c9e35
commit
2783e385a4
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 4.8.2, 2020-05-20T00:08:38. -->
|
<!-- Written by QtCreator 4.8.2, 2020-05-20T23:51:30. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
@ -14,6 +14,7 @@ public:
|
|||||||
virtual void write_install(std::string package, std::string user)=0;
|
virtual void write_install(std::string package, std::string user)=0;
|
||||||
virtual void write_remove(std::string)=0;
|
virtual void write_remove(std::string)=0;
|
||||||
virtual bool get_package_exists(std::string package)=0;
|
virtual bool get_package_exists(std::string package)=0;
|
||||||
|
virtual void create_user(std::string user, std::string pass, bool admin)=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DATA_ACCES_H
|
#endif // DATA_ACCES_H
|
||||||
|
@ -89,3 +89,11 @@ bool msql_acces::get_package_exists(std::string package){
|
|||||||
|
|
||||||
return ret>0;
|
return ret>0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void msql_acces::create_user(std::string user, std::string pass, bool admin){
|
||||||
|
sql::PreparedStatement *pstmt = con->prepareStatement("insert into users(username, passwd, admin) values(?, ?, ?)");
|
||||||
|
pstmt->setString(1,user);
|
||||||
|
pstmt->setString(2,pass);
|
||||||
|
pstmt->setBoolean(3,admin);
|
||||||
|
sql::ResultSet *res = pstmt->executeQuery();
|
||||||
|
}
|
||||||
|
@ -18,6 +18,7 @@ public:
|
|||||||
void write_install(std::string package, std::string user);
|
void write_install(std::string package, std::string user);
|
||||||
void write_remove(std::string);
|
void write_remove(std::string);
|
||||||
bool get_package_exists(std::string package);
|
bool get_package_exists(std::string package);
|
||||||
|
void create_user(std::string user, std::string pass, bool admin);
|
||||||
private:
|
private:
|
||||||
sql::Connection *con;
|
sql::Connection *con;
|
||||||
sql::Driver *driver;
|
sql::Driver *driver;
|
||||||
|
@ -31,7 +31,7 @@ bool session_manager::validate_pass(){
|
|||||||
void session_manager::start_dialog(){
|
void session_manager::start_dialog(){
|
||||||
char* buffer = new char[5];
|
char* buffer = new char[5];
|
||||||
while(true){
|
while(true){
|
||||||
this->read_data(buffer,5);
|
int n_read=this->read_data(buffer,5);
|
||||||
if(strcmp(buffer, "exec")==0){
|
if(strcmp(buffer, "exec")==0){
|
||||||
this->execute();
|
this->execute();
|
||||||
}else if(strcmp(buffer, "info")==0){
|
}else if(strcmp(buffer, "info")==0){
|
||||||
@ -40,7 +40,9 @@ void session_manager::start_dialog(){
|
|||||||
this->remove();
|
this->remove();
|
||||||
}else if(strcmp(buffer,"uinf")==0){
|
}else if(strcmp(buffer,"uinf")==0){
|
||||||
this->send_user_info();
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,6 +131,19 @@ void session_manager::send_user_info(){
|
|||||||
this->write_data("end: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){
|
int session_manager::read_data(char* input, int size){
|
||||||
return read(this->fd, input, size);
|
return read(this->fd, input, size);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ public:
|
|||||||
void send_information();
|
void send_information();
|
||||||
void send_user_info();
|
void send_user_info();
|
||||||
bool validate_pass();
|
bool validate_pass();
|
||||||
|
void create_user();
|
||||||
private:
|
private:
|
||||||
std::string appli_command(char comand[], char* n_package);
|
std::string appli_command(char comand[], char* n_package);
|
||||||
virtual int read_data(char* input, int size);
|
virtual int read_data(char* input, int size);
|
||||||
|
Loading…
Reference in New Issue
Block a user