From af9979d9a76b5f919ca611e0c2fe15d4b3c869be Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 20 Aug 2021 13:08:15 +0200 Subject: [PATCH] Postfix the fields in User with "ui" that are input from the user. --- modules/users/db_based_user.cpp | 12 ++++++------ modules/users/file_based_user.cpp | 10 +++++----- modules/users/user.cpp | 10 +++++----- modules/users/user.h | 4 ++-- modules/users/user_manager.cpp | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/modules/users/db_based_user.cpp b/modules/users/db_based_user.cpp index 2e3d9e9..2a26085 100644 --- a/modules/users/db_based_user.cpp +++ b/modules/users/db_based_user.cpp @@ -14,8 +14,8 @@ void DBBasedUser::save() { b->insert(_table_name, "username, email, rank, pre_salt, post_salt, password_hash, banned, password_reset_token, locked"); b->values(); - b->eval(name); - b->eval(email); + b->eval(nameui); + b->eval(emailui); b->val(rank); b->val(pre_salt); b->val(post_salt); @@ -37,8 +37,8 @@ void DBBasedUser::save() { } else { b->udpate(_table_name); b->set(); - b->esetp("username", name); - b->esetp("email", email); + b->esetp("username", nameui); + b->esetp("email", emailui); b->setp("rank", rank); b->setp("pre_salt", pre_salt); b->setp("post_salt", post_salt); @@ -98,8 +98,8 @@ void DBBasedUser::load() { QueryResult *r = b->run(); if (r->next_row()) { - name = r->get_cell(0); - email = r->get_cell(1); + nameui = r->get_cell(0); + emailui = r->get_cell(1); rank = r->get_cell_int(2); pre_salt = r->get_cell(3); post_salt = r->get_cell(4); diff --git a/modules/users/file_based_user.cpp b/modules/users/file_based_user.cpp index 4909174..25019b5 100644 --- a/modules/users/file_based_user.cpp +++ b/modules/users/file_based_user.cpp @@ -24,15 +24,15 @@ void FileBasedUser::set_path(const std::string &path) { void FileBasedUser::save() { //todo sanitize name! - _file_path = _path + name; + _file_path = _path + nameui; rapidjson::Document document; document.SetObject(); document.AddMember("id", id, document.GetAllocator()); - document.AddMember("name", rapidjson::Value(name.c_str(), document.GetAllocator()), document.GetAllocator()); - document.AddMember("email", rapidjson::Value(email.c_str(), document.GetAllocator()), document.GetAllocator()); + document.AddMember("name", rapidjson::Value(nameui.c_str(), document.GetAllocator()), document.GetAllocator()); + document.AddMember("email", rapidjson::Value(emailui.c_str(), document.GetAllocator()), document.GetAllocator()); document.AddMember("rank", rank, document.GetAllocator()); document.AddMember("pre_salt", rapidjson::Value(pre_salt.c_str(), document.GetAllocator()), document.GetAllocator()); document.AddMember("post_salt", rapidjson::Value(post_salt.c_str(), document.GetAllocator()), document.GetAllocator()); @@ -94,8 +94,8 @@ void FileBasedUser::load() { rapidjson::Value uobj = data.GetObject(); id = uobj["id"].GetInt(); - name = uobj["name"].GetString(); - email = uobj["email"].GetString(); + nameui = uobj["name"].GetString(); + emailui = uobj["email"].GetString(); rank = uobj["rank"].GetInt(); pre_salt = uobj["pre_salt"].GetString(); post_salt = uobj["post_salt"].GetString(); diff --git a/modules/users/user.cpp b/modules/users/user.cpp index 200aa2e..40b4aa5 100644 --- a/modules/users/user.cpp +++ b/modules/users/user.cpp @@ -43,8 +43,8 @@ bool User::check_password(const std::string &p_password) { void User::create_password(const std::string &p_password) { //todo improve a bit - pre_salt = hash_password(name + email); - post_salt = hash_password(email + name); + pre_salt = hash_password(nameui + emailui); + post_salt = hash_password(emailui + nameui); password_hash = hash_password(p_password); } @@ -238,7 +238,7 @@ void User::handle_register_request_default(Request *request) { continue; } - if (u->email == email_val) { + if (u->emailui == email_val) { email_found = true; break; } @@ -255,8 +255,8 @@ void User::handle_register_request_default(Request *request) { if (error_str.size() == 0) { user = UserManager::get_singleton()->create_user(); - user->name = uname_val; - user->email = email_val; + user->nameui = uname_val; + user->emailui = email_val; //todo user->rank = 1; user->create_password(pass_val); diff --git a/modules/users/user.h b/modules/users/user.h index 1a1c349..30a36ea 100644 --- a/modules/users/user.h +++ b/modules/users/user.h @@ -13,8 +13,8 @@ class User : public Object { public: int id; - std::string name; - std::string email; + std::string nameui; + std::string emailui; int rank; std::string pre_salt; std::string post_salt; diff --git a/modules/users/user_manager.cpp b/modules/users/user_manager.cpp index 36e3c6a..a0a4874 100644 --- a/modules/users/user_manager.cpp +++ b/modules/users/user_manager.cpp @@ -15,7 +15,7 @@ void UserManager::add_user(User *user) { std::lock_guard lock(_mutex); _users_vec.push_back(user); - _users[user->name] = user; + _users[user->nameui] = user; } void UserManager::remove_user(User *user) { @@ -26,7 +26,7 @@ void UserManager::remove_user(User *user) { std::lock_guard lock(_mutex); - _users.erase(user->name); + _users.erase(user->nameui); for (int i = 0; i < _users_vec.size(); ++i) { if (_users_vec[i] == user) {