ClienteTFG/session_manager.cpp

85 lines
2.0 KiB
C++
Raw Normal View History

2020-05-13 00:56:26 +02:00
#include "session_manager.h"
#include "read_uses.h"
session_manager::session_manager(conexion* con)
{
this->con=con;
}
bool session_manager::loggin(std::string username, std::string passwd){
2020-05-26 18:47:14 +02:00
this->con->write_string(username);
this->con->write_string(passwd);
std::string result;
this->con->read_string(result,4);
return result=="pass";
}
bool session_manager::admin(){
std::string result;
this->con->read_string(result,5);
return result=="admin";
2020-05-13 00:56:26 +02:00
}
int session_manager::install_command(std::string package){
2020-05-16 20:52:10 +02:00
this->con->write_string("exec");
2020-05-13 00:56:26 +02:00
read_uses uses(package);
this->con->write_string(package);
if(uses.exist_file()){
this->con->write_string("y");
this->con->write_string(*uses.get_uses());
}else{
this->con->write_string("n");
}
std::string buffer;
this->con->read_string(buffer,2);
return atoi(buffer.data());
}
2020-05-16 20:52:10 +02:00
int session_manager::remove_command(std::string package){
this->con->write_string("remv");
this->con->write_string(package);
std::string buffer;
this->con->read_string(buffer,2);
return atoi(buffer.data());
}
std::list<std::string> session_manager::get_packages_info(){
std::list<std::string> ret;
std::string read;
this->con->write_string("info");
while(true){
this->con->read_string(read,256);
if(read=="end:info"){
break;
}
ret.push_back(read);
}
return ret;
}
2020-05-20 00:09:18 +02:00
std::list<std::string> session_manager::get_users_info(){
std::list<std::string> ret;
std::string read;
this->con->write_string("uinf");
while(true){
this->con->read_string(read,256);
if(read=="end:info"){
break;
}
ret.push_back(read);
}
return ret;
}
2020-05-23 19:59:55 +02:00
void session_manager::create_user(std::string username, std::string password, bool admin){
this->con->write_string("cusr");
this->con->write_string(username);
this->con->write_string(password);
this->con->write_string(admin?"t":"f");
}
2020-05-26 01:37:11 +02:00
void session_manager::remove_user(std::string username){
this->con->write_string("rusr");
this->con->write_string(username);
}