diff --git a/modules/users/SCsub b/modules/users/SCsub index 88d1e478c..219cc67c5 100644 --- a/modules/users/SCsub +++ b/modules/users/SCsub @@ -16,6 +16,9 @@ sources = [ "singleton/user_db.cpp", ] +if env['module_web_enabled']: + sources.append("web/middleware/user_session_setup_middleware.cpp") + if ARGUMENTS.get('custom_modules_shared', 'no') == 'yes': # Shared lib compilation module_env.Append(CCFLAGS=['-fPIC']) diff --git a/modules/users/config.py b/modules/users/config.py index 4c27cc3ec..c8b82fdbb 100644 --- a/modules/users/config.py +++ b/modules/users/config.py @@ -15,6 +15,8 @@ def get_doc_classes(): "UserManagerStatic", "UserManagerFile", "UserDB", + + "UserSessionSetupWebServerMiddleware", ] diff --git a/modules/users/register_types.cpp b/modules/users/register_types.cpp index ceb22225e..b23c22a02 100644 --- a/modules/users/register_types.cpp +++ b/modules/users/register_types.cpp @@ -32,6 +32,12 @@ SOFTWARE. #include "singleton/user_db.h" +#include "../modules_enabled.gen.h" + +#ifdef MODULE_WEB_ENABLED +#include "web/middleware/user_session_setup_middleware.h" +#endif + UserDB *_user_db = nullptr; void register_users_types() { @@ -45,6 +51,10 @@ void register_users_types() { _user_db = memnew(UserDB); Engine::get_singleton()->add_singleton(Engine::Singleton("UserDB", UserDB::get_singleton())); + +#ifdef MODULE_WEB_ENABLED + ClassDB::register_class(); +#endif } void unregister_users_types() { diff --git a/modules/users/web/middleware/user_session_setup_middleware.cpp b/modules/users/web/middleware/user_session_setup_middleware.cpp index 7aaee637f..ed1797542 100644 --- a/modules/users/web/middleware/user_session_setup_middleware.cpp +++ b/modules/users/web/middleware/user_session_setup_middleware.cpp @@ -1,18 +1,20 @@ #include "user_session_setup_middleware.h" +#include "../../singleton/user_db.h" +#include "../../users/user.h" #include "modules/web/http/http_session.h" #include "modules/web/http/web_server_request.h" -// returnring true means handled, false means continue -bool UserSessionSetupMiddleware::on_before_handle_request_main(Ref request) { +// returning true means handled, false means continue +bool UserSessionSetupWebServerMiddleware::_on_before_handle_request_main(Ref request) { if (request->get_session().is_valid()) { - int user_id = request->get_session()->get_int("user_id"); + int user_id = request->get_session()->get_int("user_id", -1); - if (user_id != 0) { - Ref u = UserController::get_singleton()->db_get_user(user_id); + if (user_id != -1) { + Ref u = UserDB::get_singleton()->get_user(user_id); if (u.is_valid()) { - request->reference_data["user"] = u; + request->set_meta("user", u); } else { // log request->get_session()->remove("user_id"); @@ -23,7 +25,7 @@ bool UserSessionSetupMiddleware::on_before_handle_request_main(Ref request); + bool _on_before_handle_request_main(Ref request); - UserSessionSetupMiddleware(); - ~UserSessionSetupMiddleware(); + UserSessionSetupWebServerMiddleware(); + ~UserSessionSetupWebServerMiddleware(); }; #endif