From 4975c594227a407b8ad4b2e6668083c84ebb2bae Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 26 Feb 2024 22:22:15 +0100 Subject: [PATCH] Also converted the settings page to the new templates. --- .../Main.tscn | 4 +- .../Settings.gd | 91 +------------------ .../templates/SettingsPage.tres | 26 ++++++ .../templates/SettingsPageTP.phtpl | 49 ++++++++++ .../templates/SettingsPageTP.phtpl.import | 13 +++ 5 files changed, 94 insertions(+), 89 deletions(-) create mode 100644 web/users_sqlite_bootstrap_templated/templates/SettingsPage.tres create mode 100644 web/users_sqlite_bootstrap_templated/templates/SettingsPageTP.phtpl create mode 100644 web/users_sqlite_bootstrap_templated/templates/SettingsPageTP.phtpl.import diff --git a/web/users_sqlite_bootstrap_templated/Main.tscn b/web/users_sqlite_bootstrap_templated/Main.tscn index ca1231b..26c7b8e 100644 --- a/web/users_sqlite_bootstrap_templated/Main.tscn +++ b/web/users_sqlite_bootstrap_templated/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=14 format=2] +[gd_scene load_steps=15 format=2] [ext_resource path="res://WebServerSimple.gd" type="Script" id=1] [ext_resource path="res://WebRoot.gd" type="Script" id=2] @@ -10,6 +10,7 @@ [ext_resource path="res://templates/LoginPage.tres" type="HTMLTemplate" id=8] [ext_resource path="res://templates/RegisterDefaultPage.tres" type="HTMLTemplate" id=9] [ext_resource path="res://templates/RegisterSuccessPage.tres" type="HTMLTemplate" id=10] +[ext_resource path="res://templates/SettingsPage.tres" type="HTMLTemplate" id=11] [sub_resource type="SessionSetupWebServerMiddleware" id=3] @@ -77,6 +78,7 @@ uri_segment = "settings" logged_out_render_type = 1 logged_out_redirect_url = "/user/login" script = ExtResource( 7 ) +template = ExtResource( 11 ) [node name="HTTPSessionManagerDB" type="HTTPSessionManagerDB" parent="WebServerSimple"] script = ExtResource( 3 ) diff --git a/web/users_sqlite_bootstrap_templated/Settings.gd b/web/users_sqlite_bootstrap_templated/Settings.gd index 22b491f..f3abc01 100644 --- a/web/users_sqlite_bootstrap_templated/Settings.gd +++ b/web/users_sqlite_bootstrap_templated/Settings.gd @@ -1,5 +1,7 @@ extends UserSettingsWebPage +export(HTMLTemplate) var template : HTMLTemplate + class SettingsRequestData: var error_str : String = "" var pass_val : String = "" @@ -51,95 +53,8 @@ func _render_index(request : WebServerRequest) -> void: func _render_user_page(request: WebServerRequest, data: Dictionary) -> void: #print(data) - - var user : User = data["user"] - - var b : HTMLBuilder = HTMLBuilder.new() - - # Title - b.div("row mb-4") - b.div("col-2") - b.cdiv() - - b.div("col-8") - - b.h2() - b.w("User Settings") - b.ch2() - - b.cdiv() - - b.div("col-2") - b.cdiv() - b.cdiv() - - # Errors - var error_str : String = data["error_str"] - - if !error_str.empty(): - b.div("row mb-4") - b.div("col-2") - b.cdiv() - - b.div("col-8") - b.div("alert alert-danger").attrib("role", "alert") - b.w(error_str) - b.cdiv() - b.cdiv() - - b.div("col-2") - b.cdiv() - b.cdiv() - - if error_str.empty() && request.get_method() == HTTPServerEnums.HTTP_METHOD_POST: - b.div("row mb-4") - b.div("col-2") - b.cdiv() - - b.div("col-8") - b.div("alert alert-success").attrib("role", "alert") - b.w("Save successful!") - b.cdiv() - b.cdiv() - - b.div("col-2") - b.cdiv() - b.cdiv() - - # Form - b.div("row") - b.div("col-2") - b.cdiv() - - b.div("col-8") - - if true: - b.form().method_post() - b.csrf_tokenr(request) - b.div("form-group") - b.label().fora("password_input").cls("form_label").f().w("New Password").clabel() - b.input_password("password", "", "*******", "form-control", "password_input") - b.cdiv() - - b.div("form-group") - b.label().fora("password_check_input").cls("form_label").f().w("New Password again").clabel() - b.input_password("password_check", "", "*******", "form-control", "password_check_input") - b.cdiv() - - b.button().type("submit").cls("btn btn-outline-primary mt-3").f().w("Save").cbutton() - - b.cform() - - b.cdiv() - - b.div("col-2") - b.cdiv() - b.cdiv() - - - b.write_tag() - request.body += b.result + request.body += template.render(request, data) request.compile_and_send_body() func _ready() -> void: diff --git a/web/users_sqlite_bootstrap_templated/templates/SettingsPage.tres b/web/users_sqlite_bootstrap_templated/templates/SettingsPage.tres new file mode 100644 index 0000000..063b3de --- /dev/null +++ b/web/users_sqlite_bootstrap_templated/templates/SettingsPage.tres @@ -0,0 +1,26 @@ +[gd_resource type="HTMLTemplate" load_steps=3 format=2] + +[ext_resource path="res://templates/SettingsPageTP.phtpl" type="HTMLTemplateData" id=1] + +[sub_resource type="GDScript" id=1] +script/source = "extends HTMLTemplate + +func _render(request: WebServerRequest, data: Dictionary) -> String: + data[\"csrf_token\"] = request.get_csrf_token() + + var error_str : String = data[\"error_str\"] + + if !error_str.empty(): + data[\"error_str\"] = get_and_render_template(@\"Error\", data) + + if error_str.empty() && request.get_method() == HTTPServerEnums.HTTP_METHOD_POST: + data[\"error_str\"] = get_and_render_template(@\"Success\", data) + + return get_and_render_template(@\"Settings\", data) +" + +[resource] +templates = [ ExtResource( 1 ) ] +template_override/add_key_button = null +template_defaults/add_key_button = null +script = SubResource( 1 ) diff --git a/web/users_sqlite_bootstrap_templated/templates/SettingsPageTP.phtpl b/web/users_sqlite_bootstrap_templated/templates/SettingsPageTP.phtpl new file mode 100644 index 0000000..fcc6877 --- /dev/null +++ b/web/users_sqlite_bootstrap_templated/templates/SettingsPageTP.phtpl @@ -0,0 +1,49 @@ + +[ Error ] +
+
+
+ +
+
+
+ +[ Success ] +
+
+
+ +
+
+
+ +[ Settings ] +
+
+

User Settings

+
+
+{{ pr(error_str) }} +
+
+ +
+
+ + +
+ + +
+ +
+ + +
+ + +
+
+ +
+
diff --git a/web/users_sqlite_bootstrap_templated/templates/SettingsPageTP.phtpl.import b/web/users_sqlite_bootstrap_templated/templates/SettingsPageTP.phtpl.import new file mode 100644 index 0000000..a76c83e --- /dev/null +++ b/web/users_sqlite_bootstrap_templated/templates/SettingsPageTP.phtpl.import @@ -0,0 +1,13 @@ +[remap] + +importer="html_template_data" +type="HTMLTemplateData" +path="res://.import/SettingsPageTP.phtpl-edc6f5910c86fd5d50b7b412fc14029e.res" + +[deps] + +source_file="res://templates/SettingsPageTP.phtpl" +dest_files=[ "res://.import/SettingsPageTP.phtpl-edc6f5910c86fd5d50b7b412fc14029e.res" ] + +[params] +