From caa93f89b0e4da418d7426edd51b14a911ef61be Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 22 Jul 2022 11:45:12 +0200 Subject: [PATCH] Uncommented / fixed the methods that take WebServerRequest in HTMLBuilder and it's bind class. --- modules/web/html/html_builder.cpp | 13 ++++++------- modules/web/html/html_builder.h | 7 +++++-- modules/web/html/html_builder_bind.cpp | 20 +++++++------------- modules/web/html/html_builder_bind.h | 5 +++-- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/modules/web/html/html_builder.cpp b/modules/web/html/html_builder.cpp index 6930cb539..772763401 100644 --- a/modules/web/html/html_builder.cpp +++ b/modules/web/html/html_builder.cpp @@ -1,5 +1,7 @@ #include "html_builder.h" +#include "../http/web_server_request.h" + HTMLTag *HTMLTag::str(const String &str) { result += " " + str; @@ -2573,14 +2575,12 @@ HTMLBuilder *HTMLBuilder::form_post(const String &action, const String &cls, con return this; } -/* -HTMLBuilder *HTMLBuilder::form_post(const String &action, Request *request, const String &cls, const String &id) { +HTMLBuilder *HTMLBuilder::form_postr(const String &action, Ref request, const String &cls, const String &id) { form_post(action, cls, id); - csrf_token(request); + csrf_tokenr(request); return this; } -*/ HTMLTag *HTMLBuilder::input_button() { write_tag(); @@ -3326,11 +3326,10 @@ HTMLBuilder *HTMLBuilder::csrf_token(const String &token) { return this; } -/* -HTMLBuilder *HTMLBuilder::csrf_token(Request *request) { + +HTMLBuilder *HTMLBuilder::csrf_tokenr(Ref request) { return csrf_token(request->get_csrf_token()); } -*/ void HTMLBuilder::f() { write_tag(); diff --git a/modules/web/html/html_builder.h b/modules/web/html/html_builder.h index ed36e85f1..63ceb56f8 100644 --- a/modules/web/html/html_builder.h +++ b/modules/web/html/html_builder.h @@ -3,8 +3,11 @@ #include "core/ustring.h" +#include "core/reference.h" + class Request; class HTMLBuilder; +class WebServerRequest; class HTMLTag { public: @@ -470,7 +473,7 @@ public: HTMLBuilder *form_get(const String &action, const String &cls = "", const String &id = ""); HTMLBuilder *form_post(const String &action, const String &cls = "", const String &id = ""); // will add a csrf token from request - //HTMLBuilder *form_post(const String &action, Request *request, const String &cls = "", const String &id = ""); + HTMLBuilder *form_postr(const String &action, Ref request, const String &cls = "", const String &id = ""); HTMLTag *input_button(); HTMLTag *input_checkbox(); @@ -521,7 +524,7 @@ public: HTMLBuilder *input_hidden(const String &name, const String &value); HTMLBuilder *csrf_token(const String &token); - //HTMLBuilder *csrf_token(Request *request); + HTMLBuilder *csrf_tokenr(Ref request); void f(); diff --git a/modules/web/html/html_builder_bind.cpp b/modules/web/html/html_builder_bind.cpp index 784ae9d06..52b438b72 100644 --- a/modules/web/html/html_builder_bind.cpp +++ b/modules/web/html/html_builder_bind.cpp @@ -4,7 +4,7 @@ #include "core/method_bind_ext.gen.inc" -//#include "web/http/request.h" +#include "../http/web_server_request.h" bool _HTMLTag::get_simple() const { return simple; @@ -2778,14 +2778,12 @@ Ref<_HTMLTag> _HTMLBuilder::form_post(const String &action, const String &cls, c return tag; } -/* -Ref<_HTMLBuilder> _HTMLBuilder::form_post(const String &action, Request *request, const String &cls, const String &id) { +Ref<_HTMLBuilder> _HTMLBuilder::form_postr(const String &action, Ref request, const String &cls, const String &id) { form_post(action, cls, id); - csrf_token(request); + csrf_tokenr(request); return Ref<_HTMLBuilder>(this); } -*/ Ref<_HTMLBuilder> _HTMLBuilder::flabel(const String &pfor, const String &plabel, const String &cls, const String &id) { Ref<_HTMLTag> t = label(); @@ -3486,11 +3484,10 @@ Ref<_HTMLBuilder> _HTMLBuilder::csrf_token(const String &token) { return Ref<_HTMLBuilder>(this); } -/* -Ref<_HTMLBuilder> _HTMLBuilder::csrf_token(Request *request) { + +Ref<_HTMLBuilder> _HTMLBuilder::csrf_tokenr(Ref request) { return csrf_token(request->get_csrf_token()); } -*/ void _HTMLBuilder::f() { write_tag(); @@ -3893,10 +3890,7 @@ void _HTMLBuilder::_bind_methods() { ClassDB::bind_method(D_METHOD("form_get", "action", "cls", "id"), &_HTMLBuilder::form_get, "", "", ""); ClassDB::bind_method(D_METHOD("form_post", "action", "cls", "id"), &_HTMLBuilder::form_post, "", "", ""); - - //ClassDB::bind_method(D_METHOD("", "name", "cls", "id"), &_HTMLBuilder::, "", "", ""); - // will add a csrf token from request - //Ref<_HTMLBuilder> form_post(const String &action, Request *request, const String &cls = "", const String &id = ""); + ClassDB::bind_method(D_METHOD("form_postr", "action", "request", "cls", "id"), &_HTMLBuilder::form_postr, "", ""); ClassDB::bind_method(D_METHOD("input_button", "name", "value", "cls", "id"), &_HTMLBuilder::input_button, "", "", "", ""); ClassDB::bind_method(D_METHOD("input_checkbox", "name", "value", "checked", "cls", "id"), &_HTMLBuilder::input_checkbox, "", "", false, "", ""); @@ -3924,7 +3918,7 @@ void _HTMLBuilder::_bind_methods() { ClassDB::bind_method(D_METHOD("flabel", "pfor", "plabel", "cls", "id"), &_HTMLBuilder::flabel, "", ""); ClassDB::bind_method(D_METHOD("csrf_token", "token"), &_HTMLBuilder::csrf_token); - //ClassDB::bind_method(D_METHOD("csrf_token", "request"), &_HTMLBuilder::csrf_token); + ClassDB::bind_method(D_METHOD("csrf_tokenr", "request"), &_HTMLBuilder::csrf_tokenr); ClassDB::bind_method(D_METHOD("f"), &_HTMLBuilder::f); diff --git a/modules/web/html/html_builder_bind.h b/modules/web/html/html_builder_bind.h index 3b58ee0b8..a86a5f702 100644 --- a/modules/web/html/html_builder_bind.h +++ b/modules/web/html/html_builder_bind.h @@ -7,6 +7,7 @@ #include "core/reference.h" class _HTMLBuilder; +class WebServerRequest; class _HTMLTag : public Reference { GDCLASS(_HTMLTag, Reference) @@ -472,7 +473,7 @@ public: Ref<_HTMLTag> form_get(const String &action = "", const String &cls = "", const String &id = ""); Ref<_HTMLTag> form_post(const String &action = "", const String &cls = "", const String &id = ""); // will add a csrf token from request - //Ref<_HTMLBuilder> form_post(const String &action, Request *request, const String &cls = "", const String &id = ""); + Ref<_HTMLBuilder> form_postr(const String &action, Ref request, const String &cls = "", const String &id = ""); Ref<_HTMLTag> input_button(const String &name = "", const String &value = "", const String &cls = "", const String &id = ""); Ref<_HTMLTag> input_checkbox(const String &name = "", const String &value = "", const bool checked = false, const String &cls = "", const String &id = ""); @@ -500,7 +501,7 @@ public: Ref<_HTMLBuilder> flabel(const String &pfor, const String &plabel, const String &cls = "", const String &id = ""); Ref<_HTMLBuilder> csrf_token(const String &token); - //Ref<_HTMLBuilder> csrf_token(Request *request); + Ref<_HTMLBuilder> csrf_tokenr(Ref request); void f();