Removed sessions from users.

This commit is contained in:
Relintai 2021-08-22 22:17:47 +02:00
parent 8fa6548e44
commit a4e3f5d3cd
3 changed files with 0 additions and 112 deletions

View File

@ -22,47 +22,6 @@
#include "core/utils.h" #include "core/utils.h"
#include "user_model.h" #include "user_model.h"
void User::register_sessions() {
//todo rework this
if (sessions.size() == 0) {
return;
}
SessionManager *sm = SessionManager::get_singleton();
if (!sm) {
printf("ERROR: UserManager::add_user SessionManager singleton is null, please allocate one!\n");
return;
}
for (int i = 0; i < sessions.size(); ++i) {
HTTPSession *session = new HTTPSession();
session->session_id = sessions[i];
session->add_reference("user", Ref<Reference>(this));
sm->add_session(session);
}
}
void User::unregister_sessions() {
if (sessions.size() == 0) {
return;
}
SessionManager *sm = SessionManager::get_singleton();
if (!sm) {
printf("ERROR: UserManager::remove_user SessionManager singleton is null, please allocate one!\n");
return;
}
for (int i = 0; i < sessions.size(); ++i) {
sm->delete_session(sessions[i]);
}
}
void User::file_save() { void User::file_save() {
} }
void User::file_load() { void User::file_load() {
@ -217,7 +176,6 @@ User::User() :
} }
User::~User() { User::~User() {
unregister_sessions();
} }
std::string User::_path = "./"; std::string User::_path = "./";

View File

@ -25,9 +25,6 @@ public:
std::string password_reset_token; std::string password_reset_token;
bool locked; bool locked;
void register_sessions();
void unregister_sessions();
void file_save(); void file_save();
void file_load(); void file_load();
void file_ensure_directory_exist(); void file_ensure_directory_exist();

View File

@ -42,22 +42,6 @@ Ref<User> UserModel::get_user(const int id) {
user->password_reset_token = r->get_cell(7); user->password_reset_token = r->get_cell(7);
user->locked = r->get_cell_bool(8); user->locked = r->get_cell_bool(8);
b->query_result = "";
//todo remove this, sessions should have their own model
b->select("session_id");
b->from(_table_name + "_sessions");
b->where()->wp("user_id", id);
b->end_command();
r = b->run();
while (r->next_row()) {
user->sessions.push_back(r->get_cell(0));
}
user->register_sessions();
return user; return user;
} }
@ -93,22 +77,6 @@ Ref<User> UserModel::get_user(const std::string &user_name_input) {
user->password_reset_token = r->get_cell(7); user->password_reset_token = r->get_cell(7);
user->locked = r->get_cell_bool(8); user->locked = r->get_cell_bool(8);
b->query_result = "";
//todo remove this, sessions should have their own model
b->select("session_id");
b->from(_table_name + "_sessions");
b->where()->wp("user_id", user->id);
b->end_command();
r = b->run();
while (r->next_row()) {
user->sessions.push_back(r->get_cell(0));
}
user->register_sessions();
return user; return user;
} }
@ -158,28 +126,6 @@ void UserModel::save_user(Ref<User> &user) {
b->run_query(); b->run_query();
} }
if (user->id == 0) {
return;
}
b->reset();
b->del(_table_name + "_sessions")->where()->wp("user_id", user->id)->end_command();
//b->print();
b->end_command();
b->run_query();
b->reset();
for (int i = 0; i < user->sessions.size(); ++i) {
b->insert(_table_name + "_sessions")->values()->val(user->id)->val(user->sessions[i])->cvalues()->end_command();
}
//b->print();
b->run_query();
} }
std::vector<Ref<User> > UserModel::get_all() { std::vector<Ref<User> > UserModel::get_all() {
@ -275,24 +221,11 @@ void UserModel::create_table() {
tb->ccreate_table(); tb->ccreate_table();
tb->run_query(); tb->run_query();
//tb->print(); //tb->print();
//todo sessions need to be separate
tb->result = "";
tb->create_table(_table_name + "_sessions");
tb->integer("user_id")->not_null()->next_row();
tb->varchar("session_id", 100)->next_row();
tb->foreign_key("user_id");
tb->references("user", "id");
tb->ccreate_table();
//tb->print();
tb->run_query();
} }
void UserModel::drop_table() { void UserModel::drop_table() {
Ref<TableBuilder> tb = DatabaseManager::get_singleton()->ddb->get_table_builder(); Ref<TableBuilder> tb = DatabaseManager::get_singleton()->ddb->get_table_builder();
tb->drop_table_if_exists(_table_name)->run_query(); tb->drop_table_if_exists(_table_name)->run_query();
tb->drop_table_if_exists(_table_name + "_sessions")->run_query();
} }
void UserModel::migrate() { void UserModel::migrate() {
drop_table(); drop_table();