Register page initial templated setup.

This commit is contained in:
Relintai 2024-02-26 21:00:33 +01:00
parent abf64d6d10
commit 52480b4c1d
8 changed files with 217 additions and 120 deletions

View File

@ -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://WebServerSimple.gd" type="Script" id=1]
[ext_resource path="res://WebRoot.gd" type="Script" id=2] [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://Register.gd" type="Script" id=6]
[ext_resource path="res://Settings.gd" type="Script" id=7] [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/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] [sub_resource type="SessionSetupWebServerMiddleware" id=3]
@ -62,6 +64,8 @@ logged_in_render_type = 1
logged_in_redirect_url = "/" logged_in_redirect_url = "/"
redirect_on_success_url = "/user/login" redirect_on_success_url = "/user/login"
script = ExtResource( 6 ) script = ExtResource( 6 )
register_default = ExtResource( 9 )
register_success = ExtResource( 10 )
[node name="Logout" type="UserLogoutWebPage" parent="WebServerSimple/WebRoot/UserWebPage"] [node name="Logout" type="UserLogoutWebPage" parent="WebServerSimple/WebRoot/UserWebPage"]
uri_segment = "logout" uri_segment = "logout"

View File

@ -1,5 +1,8 @@
extends UserRegisterWebPage extends UserRegisterWebPage
export(HTMLTemplate) var register_default : HTMLTemplate
export(HTMLTemplate) var register_success : HTMLTemplate
var _registration_validator : FormValidator = null var _registration_validator : FormValidator = null
func log_registration_error(uname_val : String, email_val : String, error_str : String) -> void: 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: func render_register_success(request: WebServerRequest, data: Dictionary) -> void:
var b : HTMLBuilder = HTMLBuilder.new() data["redirect_on_success_url"] = redirect_on_success_url
request.body += register_success.render(request, data)
# 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() request.compile_and_send_body()
func render_register_default(request: WebServerRequest, data: Dictionary) -> void: func render_register_default(request: WebServerRequest, data: Dictionary) -> void:
var b : HTMLBuilder = HTMLBuilder.new() request.body += register_default.render(request, data)
# 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() request.compile_and_send_body()

View File

@ -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 )

View File

@ -0,0 +1,96 @@
[ Error ]
<div class="row mb-4">
<div class="col-2"></div>
<div class="col-8">
<div class="alert alert-danger" role="alert">{{ pr(error_str) }}</div>
</div>
<div class="col-2"></div>
</div>
[ 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()

View File

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

View File

@ -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 )

View File

@ -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()

View File

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