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 ] +