From 52480b4c1dd1d583ef2415b8a617244690182bdd Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 26 Feb 2024 21:00:33 +0100 Subject: [PATCH] Register page initial templated setup. --- .../Main.tscn | 6 +- .../Register.gd | 125 +----------------- .../templates/RegisterDefaultPage.tres | 26 ++++ .../templates/RegisterDefaultPageTD.phtpl | 96 ++++++++++++++ .../RegisterDefaultPageTD.phtpl.import | 13 ++ .../templates/RegisterSuccessPage.tres | 16 +++ .../templates/RegisterSuccessPageTD.phtpl | 42 ++++++ .../RegisterSuccessPageTD.phtpl.import | 13 ++ 8 files changed, 217 insertions(+), 120 deletions(-) create mode 100644 web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPage.tres create mode 100644 web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPageTD.phtpl create mode 100644 web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPageTD.phtpl.import create mode 100644 web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPage.tres create mode 100644 web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPageTD.phtpl create mode 100644 web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPageTD.phtpl.import diff --git a/web/users_sqlite_bootstrap_templated/Main.tscn b/web/users_sqlite_bootstrap_templated/Main.tscn index 6df9119..ca1231b 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=12 format=2] +[gd_scene load_steps=14 format=2] [ext_resource path="res://WebServerSimple.gd" type="Script" id=1] [ext_resource path="res://WebRoot.gd" type="Script" id=2] @@ -8,6 +8,8 @@ [ext_resource path="res://Register.gd" type="Script" id=6] [ext_resource path="res://Settings.gd" type="Script" id=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] [sub_resource type="SessionSetupWebServerMiddleware" id=3] @@ -62,6 +64,8 @@ logged_in_render_type = 1 logged_in_redirect_url = "/" redirect_on_success_url = "/user/login" script = ExtResource( 6 ) +register_default = ExtResource( 9 ) +register_success = ExtResource( 10 ) [node name="Logout" type="UserLogoutWebPage" parent="WebServerSimple/WebRoot/UserWebPage"] uri_segment = "logout" diff --git a/web/users_sqlite_bootstrap_templated/Register.gd b/web/users_sqlite_bootstrap_templated/Register.gd index 6f6bb82..71b743c 100644 --- a/web/users_sqlite_bootstrap_templated/Register.gd +++ b/web/users_sqlite_bootstrap_templated/Register.gd @@ -1,5 +1,8 @@ extends UserRegisterWebPage +export(HTMLTemplate) var register_default : HTMLTemplate +export(HTMLTemplate) var register_success : HTMLTemplate + var _registration_validator : FormValidator = null func log_registration_error(uname_val : String, email_val : String, error_str : String) -> void: @@ -87,129 +90,13 @@ func _render_user_page(request: WebServerRequest, data: Dictionary) -> void: func render_register_success(request: WebServerRequest, data: Dictionary) -> void: - 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("Registration successful!") - b.ch2() - - b.cdiv() - - b.div("col-2") - b.cdiv() - b.cdiv() - - # msg - b.div("row") - b.div("col-2") - b.cdiv() - - b.div("col-8") - b.w("Login Here:").br() - b.br() - b.a(redirect_on_success_url) - b.w(">> Login <<") - b.ca() - b.cdiv() - - b.div("col-2") - b.cdiv() - b.cdiv() - - b.write_tag() - request.body += b.result + data["redirect_on_success_url"] = redirect_on_success_url + request.body += register_success.render(request, data) request.compile_and_send_body() func render_register_default(request: WebServerRequest, data: Dictionary) -> void: - 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("Registration") - 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() - - # 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("username_input").cls("form_label").f().w("Username").clabel() - b.input_text("username", data["uname_val"], "", "form-control", "username_input") - b.cdiv() - - b.div("form-group") - b.label().fora("email_input").cls("form_label").f().w("Email").clabel() - b.input_text("email", data["email_val"], "", "form-control", "email_input") - b.cdiv() - - b.div("form-group") - b.label().fora("password_input").cls("form_label").f().w("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("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("Register").cbutton() - - b.cform() - - b.cdiv() - - b.div("col-2") - b.cdiv() - b.cdiv() - - - b.write_tag() - request.body += b.result + request.body += register_default.render(request, data) request.compile_and_send_body() diff --git a/web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPage.tres b/web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPage.tres new file mode 100644 index 0000000..4165be5 --- /dev/null +++ b/web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPage.tres @@ -0,0 +1,26 @@ +[gd_resource type="HTMLTemplate" load_steps=3 format=2] + +[ext_resource path="res://templates/RegisterDefaultPageTD.phtpl" type="HTMLTemplateData" id=1] + +[sub_resource type="GDScript" id=1] +script/source = "extends HTMLTemplate + +func _render(request: WebServerRequest, data: Dictionary) -> String: + + + var error_str : String = data[\"error_str\"] + + if !error_str.empty(): + data[\"error_str\"] = get_and_render_template(@\"Error\", data) + + #b.input_text(\"username\", data[\"uname_val\"], \"\", \"form-control\", \"username_input\") + #b.input_text(\"email\", data[\"email_val\"], \"\", \"form-control\", \"email_input\") + + return get_and_render_template(@\"Register\", 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/RegisterDefaultPageTD.phtpl b/web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPageTD.phtpl new file mode 100644 index 0000000..1ae6fca --- /dev/null +++ b/web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPageTD.phtpl @@ -0,0 +1,96 @@ + +[ Error ] +
+
+ +
+ +
+ +
+
+ +[ Register ] +func render_register_default(request: WebServerRequest, data: Dictionary) -> void: + 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("Registration") + 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() + + # 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("username_input").cls("form_label").f().w("Username").clabel() + b.input_text("username", data["uname_val"], "", "form-control", "username_input") + b.cdiv() + + b.div("form-group") + b.label().fora("email_input").cls("form_label").f().w("Email").clabel() + b.input_text("email", data["email_val"], "", "form-control", "email_input") + b.cdiv() + + b.div("form-group") + b.label().fora("password_input").cls("form_label").f().w("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("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("Register").cbutton() + + b.cform() + + b.cdiv() + + b.div("col-2") + b.cdiv() + b.cdiv() + + + b.write_tag() + request.body += b.result + request.compile_and_send_body() diff --git a/web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPageTD.phtpl.import b/web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPageTD.phtpl.import new file mode 100644 index 0000000..6d5467e --- /dev/null +++ b/web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPageTD.phtpl.import @@ -0,0 +1,13 @@ +[remap] + +importer="html_template_data" +type="HTMLTemplateData" +path="res://.import/RegisterDefaultPageTD.phtpl-cc8ec9951908604d08d300f8bfc56f98.res" + +[deps] + +source_file="res://templates/RegisterDefaultPageTD.phtpl" +dest_files=[ "res://.import/RegisterDefaultPageTD.phtpl-cc8ec9951908604d08d300f8bfc56f98.res" ] + +[params] + diff --git a/web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPage.tres b/web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPage.tres new file mode 100644 index 0000000..12e39d6 --- /dev/null +++ b/web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPage.tres @@ -0,0 +1,16 @@ +[gd_resource type="HTMLTemplate" load_steps=3 format=2] + +[ext_resource path="res://templates/RegisterSuccessPageTD.phtpl" type="HTMLTemplateData" id=1] + +[sub_resource type="GDScript" id=1] +script/source = "extends HTMLTemplate + +func _render(request: WebServerRequest, data: Dictionary) -> String: + return get_and_render_template(@\"RegisterSuccess\", 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/RegisterSuccessPageTD.phtpl b/web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPageTD.phtpl new file mode 100644 index 0000000..80b97f3 --- /dev/null +++ b/web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPageTD.phtpl @@ -0,0 +1,42 @@ + +[ RegisterSuccess ] +func render_register_success(request: WebServerRequest, data: Dictionary) -> void: + 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("Registration successful!") + b.ch2() + + b.cdiv() + + b.div("col-2") + b.cdiv() + b.cdiv() + + # msg + b.div("row") + b.div("col-2") + b.cdiv() + + b.div("col-8") + b.w("Login Here:").br() + b.br() + b.a(redirect_on_success_url) + b.w(">> Login <<") + b.ca() + b.cdiv() + + b.div("col-2") + b.cdiv() + b.cdiv() + + b.write_tag() + request.body += b.result + request.compile_and_send_body() diff --git a/web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPageTD.phtpl.import b/web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPageTD.phtpl.import new file mode 100644 index 0000000..ede64a1 --- /dev/null +++ b/web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPageTD.phtpl.import @@ -0,0 +1,13 @@ +[remap] + +importer="html_template_data" +type="HTMLTemplateData" +path="res://.import/RegisterSuccessPageTD.phtpl-a1401583ad5a9491b7c80bf6f0b9ac04.res" + +[deps] + +source_file="res://templates/RegisterSuccessPageTD.phtpl" +dest_files=[ "res://.import/RegisterSuccessPageTD.phtpl-a1401583ad5a9491b7c80bf6f0b9ac04.res" ] + +[params] +