From c86ed59dd643095eaa3a6dd3b0f0c4769cf96697 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 1 Nov 2021 19:14:55 +0100 Subject: [PATCH] Replaced std::string and std::vectors in the user module aswell. --- modules/users/user_controller.cpp | 4 ++-- modules/users/user_controller.h | 26 +++++++++++++------------- modules/users/user_model.cpp | 24 ++++++++++++------------ modules/users/user_model.h | 25 +++++++++++++------------ 4 files changed, 40 insertions(+), 39 deletions(-) diff --git a/modules/users/user_controller.cpp b/modules/users/user_controller.cpp index 9dbff22..b2d11a7 100644 --- a/modules/users/user_controller.cpp +++ b/modules/users/user_controller.cpp @@ -19,7 +19,7 @@ void UserController::handle_request_default(Request *request) { } } - const std::string &segment = request->get_current_path_segment(); + const String &segment = request->get_current_path_segment(); if (segment == "") { handle_login_request_default(request); @@ -270,7 +270,7 @@ void UserController::render_login_success(Request *request) { } void UserController::handle_request(Ref &user, Request *request) { - const std::string &segment = request->get_current_path_segment(); + const String &segment = request->get_current_path_segment(); if (segment == "") { handle_main_page_request(user, request); diff --git a/modules/users/user_controller.h b/modules/users/user_controller.h index 7f7ed5e..b52e456 100644 --- a/modules/users/user_controller.h +++ b/modules/users/user_controller.h @@ -18,20 +18,20 @@ public: virtual void handle_request_default(Request *request); struct LoginRequestData { - std::string error_str; - std::string uname_val; - std::string pass_val; + String error_str; + String uname_val; + String pass_val; }; virtual void handle_login_request_default(Request *request); virtual void render_login_request_default(Request *request, LoginRequestData *data); struct RegisterRequestData { - std::string error_str; - std::string uname_val; - std::string email_val; - std::string pass_val; - std::string pass_check_val; + String error_str; + String uname_val; + String email_val; + String pass_val; + String pass_check_val; }; virtual void handle_register_request_default(Request *request); @@ -45,12 +45,12 @@ public: virtual void handle_main_page_request(Ref &user, Request *request); struct SettingsRequestData { - std::string error_str; + String error_str; - std::string uname_val; - std::string email_val; - std::string pass_val; - std::string pass_check_val; + String uname_val; + String email_val; + String pass_val; + String pass_check_val; }; virtual void handle_settings_request(Ref &user, Request *request); diff --git a/modules/users/user_model.cpp b/modules/users/user_model.cpp index f4b6228..d93b48a 100644 --- a/modules/users/user_model.cpp +++ b/modules/users/user_model.cpp @@ -45,7 +45,7 @@ Ref UserModel::get_user(const int id) { return user; } -Ref UserModel::get_user(const std::string &user_name_input) { +Ref UserModel::get_user(const String &user_name_input) { if (user_name_input == "") { return Ref(); } @@ -125,7 +125,7 @@ void UserModel::save_user(Ref &user) { } } -std::vector > UserModel::get_all() { +Vector > UserModel::get_all() { Ref b = DatabaseManager::get_singleton()->ddb->get_query_builder(); b->select("id, username, email, rank, pre_salt, post_salt, password_hash, banned, password_reset_token, locked"); @@ -133,7 +133,7 @@ std::vector > UserModel::get_all() { b->end_command(); //b->print(); - std::vector > users; + Vector > users; Ref r = b->run(); @@ -158,7 +158,7 @@ std::vector > UserModel::get_all() { return users; } -bool UserModel::is_username_taken(const std::string &user_name_input) { +bool UserModel::is_username_taken(const String &user_name_input) { Ref b = DatabaseManager::get_singleton()->ddb->get_query_builder(); b->select("id")->from(_table_name)->where("username")->like(user_name_input)->end_command(); @@ -167,7 +167,7 @@ bool UserModel::is_username_taken(const std::string &user_name_input) { return r->next_row(); } -bool UserModel::is_email_taken(const std::string &email_input) { +bool UserModel::is_email_taken(const String &email_input) { Ref b = DatabaseManager::get_singleton()->ddb->get_query_builder(); b->select("id")->from(_table_name)->where("username")->like(email_input)->end_command(); @@ -177,11 +177,11 @@ bool UserModel::is_email_taken(const std::string &email_input) { return r->next_row(); } -bool UserModel::check_password(const Ref &user, const std::string &p_password) { +bool UserModel::check_password(const Ref &user, const String &p_password) { return hash_password(user, p_password) == user->password_hash; } -void UserModel::create_password(Ref &user, const std::string &p_password) { +void UserModel::create_password(Ref &user, const String &p_password) { if (!user.is_valid()) { printf("Error UserModel::create_password !user.is_valid()!\n"); return; @@ -194,7 +194,7 @@ void UserModel::create_password(Ref &user, const std::string &p_password) user->password_hash = hash_password(user, p_password); } -std::string UserModel::hash_password(const Ref &user, const std::string &p_password) { +String UserModel::hash_password(const Ref &user, const String &p_password) { if (!user.is_valid()) { printf("Error UserModel::hash_password !user.is_valid()!\n"); return ""; @@ -202,9 +202,9 @@ std::string UserModel::hash_password(const Ref &user, const std::string &p Ref s = SHA256::get(); - std::string p = user->pre_salt + p_password + user->post_salt; + String p = user->pre_salt + p_password + user->post_salt; - std::string c = s->compute(p); + String c = s->compute(p); return c; } @@ -260,5 +260,5 @@ UserModel::~UserModel() { UserModel *UserModel::_self = nullptr; -std::string UserModel::_path = "./"; -std::string UserModel::_table_name = "users"; \ No newline at end of file +String UserModel::_path = "./"; +String UserModel::_table_name = "users"; \ No newline at end of file diff --git a/modules/users/user_model.h b/modules/users/user_model.h index 4f3b154..a5caee7 100644 --- a/modules/users/user_model.h +++ b/modules/users/user_model.h @@ -1,28 +1,29 @@ #ifndef USER_MODEL_H #define USER_MODEL_H +#include "core/string.h" +#include "core/containers/vector.h" + #include "core/object.h" #include "user.h" -#include -#include class UserModel : public Object { RCPP_OBJECT(UserModel, Object); public: Ref get_user(const int id); - Ref get_user(const std::string &user_name_input); + Ref get_user(const String &user_name_input); void save_user(Ref &user); - std::vector > get_all(); + Vector > get_all(); - bool is_username_taken(const std::string &user_name_input); - bool is_email_taken(const std::string &email_input); + bool is_username_taken(const String &user_name_input); + bool is_email_taken(const String &email_input); - virtual bool check_password(const Ref &user, const std::string &p_password); - virtual void create_password(Ref &user, const std::string &p_password); - virtual std::string hash_password(const Ref &user, const std::string &p_password); + virtual bool check_password(const Ref &user, const String &p_password); + virtual void create_password(Ref &user, const String &p_password); + virtual String hash_password(const Ref &user, const String &p_password); virtual void create_table(); virtual void drop_table(); @@ -36,10 +37,10 @@ public: protected: static UserModel *_self; - std::string _file_path; + String _file_path; - static std::string _path; - static std::string _table_name; + static String _path; + static String _table_name; }; #endif \ No newline at end of file