From d469473ec8e8cf0bb2c5e2fa80f57941cf292fe8 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 7 Jul 2022 00:18:37 +0200 Subject: [PATCH] Some todos / notes. --- modules/web/nodes/users/user_controller.cpp | 14 +++----------- modules/web/nodes/users/user_controller.h | 13 ++++++++++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/modules/web/nodes/users/user_controller.cpp b/modules/web/nodes/users/user_controller.cpp index c602f135f..4e8dd0913 100644 --- a/modules/web/nodes/users/user_controller.cpp +++ b/modules/web/nodes/users/user_controller.cpp @@ -56,7 +56,6 @@ void UserController::handle_login_request_default(Request *request) { LoginRequestData data; if (request->get_method() == HTTP_METHOD_POST) { - // this is probbaly not needed // it's ok for now as I need to test the validators more Vector errors; @@ -115,7 +114,6 @@ void UserController::render_login_request_default(Request *request, LoginRequest b.div()->cls("login"); { - // todo href path helper b.form()->method("POST")->href("/user/login"); { @@ -149,7 +147,6 @@ void UserController::handle_register_request_default(Request *request) { RegisterRequestData data; if (request->get_method() == HTTP_METHOD_POST) { - Vector errors; _registration_validator->validate(request, &errors); @@ -315,11 +312,9 @@ void UserController::handle_main_page_request(Ref &user, Request *request) } void UserController::handle_settings_request(Ref &user, Request *request) { - SettingsRequestData data; if (request->get_method() == HTTP_METHOD_POST) { - data.uname_val = request->get_parameter("username"); data.email_val = request->get_parameter("email"); data.pass_val = request->get_parameter("password"); @@ -408,7 +403,7 @@ void UserController::render_settings_request(Ref &user, Request *request, b.form()->method("POST")->href("/user/settings"); { b.csrf_token(request); - + b.w("Username"); b.br(); b.input()->type("text")->name("username")->placeholder(user->name_user_input)->value(data->uname_val); @@ -633,7 +628,7 @@ void UserController::db_save_user(Ref &user) { } } -Vector > UserController::db_get_all() { +Vector> UserController::db_get_all() { Ref b = get_query_builder(); b->select("id, username, email, rank, pre_salt, post_salt, password_hash, banned, password_reset_token, locked"); @@ -641,7 +636,7 @@ Vector > UserController::db_get_all() { b->end_command(); // b->print(); - Vector > users; + Vector> users; Ref r = b->run(); @@ -775,7 +770,6 @@ UserController *UserController::get_singleton() { UserController::UserController() : WebNode() { - if (_self) { printf("UserController::UserController(): Error! self is not null!/n"); } @@ -800,14 +794,12 @@ FormValidator *UserController::_profile_validator = nullptr; String UserController::_path = "./"; String UserController::_table_name = "users"; - // returnring true means handled, false means continue bool UserSessionSetupMiddleware::on_before_handle_request_main(Request *request) { if (request->session.is_valid()) { int user_id = request->session->get_int("user_id"); if (user_id != 0) { - Ref u = UserController::get_singleton()->db_get_user(user_id); if (u.is_valid()) { diff --git a/modules/web/nodes/users/user_controller.h b/modules/web/nodes/users/user_controller.h index cdbf90bcb..e993f1d04 100644 --- a/modules/web/nodes/users/user_controller.h +++ b/modules/web/nodes/users/user_controller.h @@ -12,6 +12,14 @@ class Request; class FormValidator; +//TODO +// Break this up into multiple small webnodes (per page) +// that would make this a lot more customizable +// Only User management, save, load etc should be kept here +// and this node should be expected to be autoloaded. +// It should keep get_singleton() and c++ stuff that deal with users should expect it's presence +// they should use err macros to not crash the app though + class UserController : public WebNode { RCPP_OBJECT(UserController, WebNode); @@ -69,7 +77,7 @@ public: virtual Ref db_get_user(const String &user_name_input); virtual void db_save_user(Ref &user); - virtual Vector > db_get_all(); + virtual Vector> db_get_all(); virtual Ref create_user(); @@ -114,5 +122,4 @@ public: ~UserSessionSetupMiddleware(); }; - -#endif \ No newline at end of file +#endif