From a5a327ad35639ed78df0c04cff6a820c5b4aa3bd Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 23 Jul 2022 22:08:07 +0200 Subject: [PATCH] Reimplemented UserRegisterWebPage. --- .../web/web_nodes/user_register_web_page.cpp | 26 +++++++++++++------ .../web/web_nodes/user_register_web_page.h | 11 +++++--- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/modules/users/web/web_nodes/user_register_web_page.cpp b/modules/users/web/web_nodes/user_register_web_page.cpp index ba5ab2254..2ba6fe003 100644 --- a/modules/users/web/web_nodes/user_register_web_page.cpp +++ b/modules/users/web/web_nodes/user_register_web_page.cpp @@ -14,7 +14,14 @@ #include "modules/web/http/web_server_cookie.h" #include "modules/web/http/web_server_request.h" -void UserRegisterWebPage::handle_register_request_default(Ref request) { +String UserRegisterWebPage::get_redirect_on_success_url() { + return _redirect_on_success_url; +} +void UserRegisterWebPage::set_redirect_on_success_url(const String &val) { + _redirect_on_success_url = val; +} + +void UserRegisterWebPage::_render_index(Ref request) { RegisterRequestData data; if (request->get_method() == HTTPServerEnums::HTTP_METHOD_POST) { @@ -69,7 +76,7 @@ void UserRegisterWebPage::render_register_success(Ref request) { b.w("Registration successful! You can now log in!"); b.br(); - b.a()->href("/user/login"); + b.a()->href(_redirect_on_success_url); b.w(">> Login <<"); b.ca(); } @@ -139,12 +146,6 @@ void UserRegisterWebPage::render_register_request_default(Ref request->compile_and_send_body(); } -void UserRegisterWebPage::render_already_logged_in_error(Ref request) { - request->body += "You are already logged in."; - - request->compile_and_send_body(); -} - UserRegisterWebPage::UserRegisterWebPage() { // Registration _registration_validator.instance(); @@ -160,7 +161,16 @@ UserRegisterWebPage::UserRegisterWebPage() { _registration_validator->new_field("password_check", "Password check")->need_to_match("password"); _registration_validator->new_field("email", "Email")->need_to_exist()->need_to_be_email(); + + _logged_out_render_type = RENDER_TYPE_RENDER; + _logged_in_render_type = RENDER_TYPE_ERROR; } UserRegisterWebPage::~UserRegisterWebPage() { } + +void UserRegisterWebPage::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_redirect_on_success_url"), &UserRegisterWebPage::get_redirect_on_success_url); + ClassDB::bind_method(D_METHOD("set_redirect_on_success_url", "val"), &UserRegisterWebPage::set_redirect_on_success_url); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "redirect_on_success_url"), "set_redirect_on_success_url", "get_redirect_on_success_url"); +} diff --git a/modules/users/web/web_nodes/user_register_web_page.h b/modules/users/web/web_nodes/user_register_web_page.h index ba9c63180..7f5c384b9 100644 --- a/modules/users/web/web_nodes/user_register_web_page.h +++ b/modules/users/web/web_nodes/user_register_web_page.h @@ -15,6 +15,9 @@ class UserRegisterWebPage : public UserWebPage { GDCLASS(UserRegisterWebPage, UserWebPage); public: + String get_redirect_on_success_url(); + void set_redirect_on_success_url(const String &val); + struct RegisterRequestData { String error_str; String uname_val; @@ -23,18 +26,20 @@ public: String pass_check_val; }; - virtual void handle_register_request_default(Ref request); + void _render_index(Ref request); virtual void render_register_request_default(Ref request, RegisterRequestData *data); virtual void render_register_success(Ref request); - virtual void render_already_logged_in_error(Ref request); - UserRegisterWebPage(); ~UserRegisterWebPage(); protected: + static void _bind_methods(); + Ref _registration_validator; Ref _profile_validator; + + String _redirect_on_success_url; }; #endif