diff --git a/modules/users/web/web_nodes/user_login_web_page.cpp b/modules/users/web/web_nodes/user_login_web_page.cpp index cf0e690f9..68737e7f8 100644 --- a/modules/users/web/web_nodes/user_login_web_page.cpp +++ b/modules/users/web/web_nodes/user_login_web_page.cpp @@ -14,7 +14,14 @@ #include "modules/web/http/web_server_cookie.h" #include "modules/web/http/web_server_request.h" -void UserLoginWebPage::handle_login_request_default(Ref request) { +String UserLoginWebPage::get_redirect_on_success_url() { + return _redirect_on_success_url; +} +void UserLoginWebPage::set_redirect_on_success_url(const String &val) { + _redirect_on_success_url = val; +} + +void UserLoginWebPage::_render_index(Ref request) { LoginRequestData data; if (request->get_method() == HTTPServerEnums::HTTP_METHOD_POST) { @@ -41,8 +48,8 @@ void UserLoginWebPage::handle_login_request_default(Ref reques Ref c; c.instance(); - c->set_data("session_id", session->session_id); - //c.path = "/"; + c->set_data("session_id", session->get_session_id()); + c->set_path("/"); request->response_add_cookie(c); render_login_success(request); @@ -104,17 +111,11 @@ void UserLoginWebPage::render_login_request_default(Ref reques request->compile_and_send_body(); } -void UserLoginWebPage::render_already_logged_in_error(Ref request) { - request->body += "You are already logged in."; - - request->compile_and_send_body(); -} - void UserLoginWebPage::render_login_success(Ref request) { request->body = "Login Success!
"; // request->compile_and_send_body(); - request->send_redirect("/user/settings"); + request->send_redirect(_redirect_on_success_url); } UserLoginWebPage::UserLoginWebPage() { @@ -126,7 +127,16 @@ UserLoginWebPage::UserLoginWebPage() { pw->need_to_exist(); pw->need_to_have_lowercase_character()->need_to_have_uppercase_character(); pw->need_minimum_length(5); + + _logged_out_render_type = RENDER_TYPE_RENDER; + _logged_in_render_type = RENDER_TYPE_ERROR; } UserLoginWebPage::~UserLoginWebPage() { } + +void UserLoginWebPage::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_redirect_on_success_url"), &UserLoginWebPage::get_redirect_on_success_url); + ClassDB::bind_method(D_METHOD("set_redirect_on_success_url", "val"), &UserLoginWebPage::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_login_web_page.h b/modules/users/web/web_nodes/user_login_web_page.h index 97e376894..0a56cedb0 100644 --- a/modules/users/web/web_nodes/user_login_web_page.h +++ b/modules/users/web/web_nodes/user_login_web_page.h @@ -15,23 +15,29 @@ class UserLoginWebPage : public UserWebPage { GDCLASS(UserLoginWebPage, UserWebPage); public: + String get_redirect_on_success_url(); + void set_redirect_on_success_url(const String &val); + struct LoginRequestData { String error_str; String uname_val; String pass_val; }; - virtual void handle_login_request_default(Ref request); - virtual void render_login_request_default(Ref request, LoginRequestData *data); + void _render_index(Ref request); - virtual void render_already_logged_in_error(Ref request); + virtual void render_login_request_default(Ref request, LoginRequestData *data); virtual void render_login_success(Ref request); UserLoginWebPage(); ~UserLoginWebPage(); protected: + static void _bind_methods(); + Ref _login_validator; + + String _redirect_on_success_url; }; #endif