diff --git a/modules/users/user.cpp b/modules/users/user.cpp index a772c13..452fefd 100644 --- a/modules/users/user.cpp +++ b/modules/users/user.cpp @@ -22,47 +22,6 @@ #include "core/utils.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(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_load() { @@ -217,7 +176,6 @@ User::User() : } User::~User() { - unregister_sessions(); } std::string User::_path = "./"; diff --git a/modules/users/user.h b/modules/users/user.h index a008355..949a516 100644 --- a/modules/users/user.h +++ b/modules/users/user.h @@ -25,9 +25,6 @@ public: std::string password_reset_token; bool locked; - void register_sessions(); - void unregister_sessions(); - void file_save(); void file_load(); void file_ensure_directory_exist(); diff --git a/modules/users/user_model.cpp b/modules/users/user_model.cpp index f8fb84b..d361c04 100644 --- a/modules/users/user_model.cpp +++ b/modules/users/user_model.cpp @@ -42,22 +42,6 @@ Ref UserModel::get_user(const int id) { user->password_reset_token = r->get_cell(7); 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; } @@ -93,22 +77,6 @@ Ref UserModel::get_user(const std::string &user_name_input) { user->password_reset_token = r->get_cell(7); 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; } @@ -158,28 +126,6 @@ void UserModel::save_user(Ref &user) { 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 > UserModel::get_all() { @@ -275,24 +221,11 @@ void UserModel::create_table() { tb->ccreate_table(); tb->run_query(); //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() { Ref tb = DatabaseManager::get_singleton()->ddb->get_table_builder(); tb->drop_table_if_exists(_table_name)->run_query(); - tb->drop_table_if_exists(_table_name + "_sessions")->run_query(); } void UserModel::migrate() { drop_table();