diff --git a/web/users_sqlite_bootstrap_templated/Login.gd b/web/users_sqlite_bootstrap_templated/Login.gd index 7b7b26d..e39599c 100644 --- a/web/users_sqlite_bootstrap_templated/Login.gd +++ b/web/users_sqlite_bootstrap_templated/Login.gd @@ -1,5 +1,7 @@ extends UserLoginWebPage +export(HTMLTemplate) var login_template : HTMLTemplate + var _login_validator : FormValidator = null #func _render_index(request: WebServerRequest) -> void: @@ -86,78 +88,8 @@ func _render_user_page(request: WebServerRequest, data: Dictionary) -> void: if type == "render_login_success": request.send_redirect(redirect_on_success_url) return - - - 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("Login") - 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("password_input").cls("form_label").f().w("Password").clabel() - b.input_password("password", "", "*******", "form-control", "password_input") - b.cdiv() - - b.button().type("submit").cls("btn btn-outline-primary mt-3").f().w("Send").cbutton() - - b.cform() - - b.cdiv() - - b.div("col-2") - b.cdiv() - b.cdiv() - - b.write_tag() - request.body += b.result + + request.body += login_template.render(request, data) request.compile_and_send_body() func _ready() -> void: diff --git a/web/users_sqlite_bootstrap_templated/Main.tscn b/web/users_sqlite_bootstrap_templated/Main.tscn index 1f1790f..6df9119 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=11 format=2] +[gd_scene load_steps=12 format=2] [ext_resource path="res://WebServerSimple.gd" type="Script" id=1] [ext_resource path="res://WebRoot.gd" type="Script" id=2] @@ -7,6 +7,7 @@ [ext_resource path="res://Login.gd" type="Script" id=5] [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] [sub_resource type="SessionSetupWebServerMiddleware" id=3] @@ -53,6 +54,7 @@ uri_segment = "login" logged_in_render_type = 1 logged_in_redirect_url = "/" script = ExtResource( 5 ) +login_template = ExtResource( 8 ) [node name="Register" type="UserRegisterWebPage" parent="WebServerSimple/WebRoot/UserWebPage"] uri_segment = "register" diff --git a/web/users_sqlite_bootstrap_templated/templates/LoginPage.tres b/web/users_sqlite_bootstrap_templated/templates/LoginPage.tres new file mode 100644 index 0000000..c601a9e --- /dev/null +++ b/web/users_sqlite_bootstrap_templated/templates/LoginPage.tres @@ -0,0 +1,27 @@ +[gd_resource type="HTMLTemplate" load_steps=3 format=2] + +[ext_resource path="res://templates/LoginPageTD.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(@\"LoginErrorStrTemplate\", data) + + var uname_val : String = data[\"uname_val\"] + data[\"username_prev_value\"] = \"\" + + if (!uname_val.empty()): + data[\"username_prev_value\"] = 'value=\"' + uname_val + '\"' + + return get_and_render_template(@\"Login\", 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/LoginPageTD.phtpl b/web/users_sqlite_bootstrap_templated/templates/LoginPageTD.phtpl new file mode 100644 index 0000000..c6fdab8 --- /dev/null +++ b/web/users_sqlite_bootstrap_templated/templates/LoginPageTD.phtpl @@ -0,0 +1,48 @@ + +[ Login ] +
+
+ +
+

Login

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