add normal user restrictions

This commit is contained in:
Guillermo Roche 2020-05-26 18:48:31 +02:00
parent b0c78dde76
commit df772fec57
4 changed files with 18 additions and 0 deletions

View File

@ -9,6 +9,7 @@ class data_acces
public:
data_acces();
virtual std::string get_passwd(std::string username) = 0;
virtual bool get_admin(std::string)=0;
virtual std::list<std::string> get_pinfo()=0;
virtual std::list<std::string> get_uinfo()=0;
virtual void write_install(std::string package, std::string user)=0;

View File

@ -19,6 +19,17 @@ std::string msql_acces::get_passwd(std::string username){
return ret;
}
bool msql_acces::get_admin(std::string username){
sql::PreparedStatement *pstmt = con->prepareStatement("select admin from users where username=?");
pstmt->setString(1,username);
sql::ResultSet *res = pstmt->executeQuery();
bool ret=false;
while(res->next())
ret = res->getBoolean("admin");
delete res;
return ret;
}
std::list<std::string> msql_acces::get_pinfo(){
sql::PreparedStatement *pstmt =
con->prepareStatement("select packages.name, packages.created, packages.uses, users.username "

View File

@ -13,6 +13,7 @@ class msql_acces : public data_acces
public:
msql_acces();
std::string get_passwd(std::string username);
bool get_admin(std::string);
std::list<std::string> get_pinfo();
std::list<std::string> get_uinfo();
void write_install(std::string package, std::string user);

View File

@ -20,6 +20,11 @@ bool session_manager::validate_pass(){
std::string pass=buffer;
if(this->data->get_passwd(user)==pass){
this->write_data("pass");
if(this->data->get_admin(user)){
this->write_data("admin");
}else{
this->write_data("norma");
}
this->user=user;
return true;
}else{