mirror of
https://github.com/Relintai/pandemonium_demo_projects.git
synced 2024-12-21 13:56:50 +01:00
Added a new demo showing an sqlite web + user management based setup.
This commit is contained in:
parent
cbcc6ecf9c
commit
b2832cb3a8
10
web/users_sqlite/HTTPSessionManagerDB.gd
Normal file
10
web/users_sqlite/HTTPSessionManagerDB.gd
Normal file
@ -0,0 +1,10 @@
|
||||
extends HTTPSessionManagerDB
|
||||
|
||||
func _ready() -> void:
|
||||
DatabaseManager.connect("initialized", self, "on_databases_initialized", [], CONNECT_ONESHOT)
|
||||
# You could also connect to the migration signal, and write migrations if you need them
|
||||
|
||||
func on_databases_initialized() -> void:
|
||||
# Load sessions after the databases are initialized
|
||||
# This happens on the Main node.
|
||||
call_deferred("load_sessions")
|
35
web/users_sqlite/Main.gd
Normal file
35
web/users_sqlite/Main.gd
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
extends Node
|
||||
|
||||
export(String) var database_location : String = "user://database.sqlite"
|
||||
|
||||
func _ready() -> void:
|
||||
var d : Directory = Directory.new()
|
||||
var bd : String = database_location.get_base_dir()
|
||||
var loc : String = d.get_filesystem_abspath_for(bd).append_path(database_location.get_file())
|
||||
|
||||
var file : File = File.new()
|
||||
if !file.file_exists(loc):
|
||||
PLogger.log_message("Database file doesn't exists, will run migrations!")
|
||||
call_deferred("migrate")
|
||||
else:
|
||||
call_deferred("db_initialized")
|
||||
|
||||
var db : SQLite3Database = SQLite3Database.new()
|
||||
db.connection_string = loc
|
||||
DatabaseManager.add_database(db)
|
||||
|
||||
|
||||
func migrate() -> void:
|
||||
PLogger.log_message("Running migrations!")
|
||||
DatabaseManager.connect("migration", self, "_migration")
|
||||
DatabaseManager.migrate(true, false, 0)
|
||||
|
||||
call_deferred("db_initialized")
|
||||
|
||||
func db_initialized() -> void:
|
||||
DatabaseManager.initialized()
|
||||
|
||||
func _migration(clear: bool, should_seed: bool, pseed: int) -> void:
|
||||
#create admin account
|
||||
pass
|
74
web/users_sqlite/Main.tscn
Normal file
74
web/users_sqlite/Main.tscn
Normal file
@ -0,0 +1,74 @@
|
||||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://WebServerSimple.gd" type="Script" id=1]
|
||||
[ext_resource path="res://WebRoot.gd" type="Script" id=2]
|
||||
[ext_resource path="res://HTTPSessionManagerDB.gd" type="Script" id=3]
|
||||
[ext_resource path="res://Main.gd" type="Script" id=4]
|
||||
|
||||
[sub_resource type="SessionSetupWebServerMiddleware" id=3]
|
||||
|
||||
[sub_resource type="UserSessionSetupWebServerMiddleware" id=4]
|
||||
|
||||
[sub_resource type="CSRFTokenWebServerMiddleware" id=5]
|
||||
ignored_urls = PoolStringArray( "/user/login", "/user/register" )
|
||||
|
||||
[node name="Main" type="Node"]
|
||||
script = ExtResource( 4 )
|
||||
|
||||
[node name="UserManagerDB" type="UserManagerDB" parent="."]
|
||||
|
||||
[node name="WebServerSimple" type="WebServerSimple" parent="."]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="WebRoot" type="WebRoot" parent="WebServerSimple"]
|
||||
www_root_path = "res://www/"
|
||||
middlewares = [ SubResource( 3 ), SubResource( 4 ), SubResource( 5 ) ]
|
||||
script = ExtResource( 2 )
|
||||
menu_str = "<br>
|
||||
<a href=\"/\">index</a><br>
|
||||
<a href=\"/user/login\">login</a><br>
|
||||
<a href=\"/user/register\">register</a><br>
|
||||
<a href=\"/user/settings\">settings</a><br>
|
||||
<a href=\"/user/logout\">logout</a><br>
|
||||
<br>
|
||||
|
||||
"
|
||||
|
||||
[node name="StaticWebPage" type="StaticWebPage" parent="WebServerSimple/WebRoot"]
|
||||
uri_segment = "/"
|
||||
data = "
|
||||
You can go and log in on the users page here: <a href=\"/user/login\">Login</a><br>
|
||||
<br>
|
||||
Note that in this demo sessions and users are saved in an SQLite database here: \"user://database.sqlite\"<br>
|
||||
<br>
|
||||
There are no users by default.<br>
|
||||
<br>
|
||||
"
|
||||
|
||||
[node name="UserWebPage" type="UserWebPage" parent="WebServerSimple/WebRoot"]
|
||||
uri_segment = "user"
|
||||
logged_out_render_type = 1
|
||||
logged_out_redirect_url = "/user/login"
|
||||
|
||||
[node name="UserLoginWebPage" type="UserLoginWebPage" parent="WebServerSimple/WebRoot/UserWebPage"]
|
||||
uri_segment = "login"
|
||||
logged_in_render_type = 1
|
||||
logged_in_redirect_url = "/"
|
||||
|
||||
[node name="UserRegisterWebPage" type="UserRegisterWebPage" parent="WebServerSimple/WebRoot/UserWebPage"]
|
||||
uri_segment = "register"
|
||||
logged_in_render_type = 1
|
||||
logged_in_redirect_url = "/"
|
||||
|
||||
[node name="UserLogoutWebPage" type="UserLogoutWebPage" parent="WebServerSimple/WebRoot/UserWebPage"]
|
||||
uri_segment = "logout"
|
||||
logged_out_render_type = 1
|
||||
logged_out_redirect_url = "/"
|
||||
|
||||
[node name="UserSettingsWebPage" type="UserSettingsWebPage" parent="WebServerSimple/WebRoot/UserWebPage"]
|
||||
uri_segment = "settings"
|
||||
logged_out_render_type = 1
|
||||
logged_out_redirect_url = "/user/login"
|
||||
|
||||
[node name="HTTPSessionManagerDB" type="HTTPSessionManagerDB" parent="WebServerSimple"]
|
||||
script = ExtResource( 3 )
|
18
web/users_sqlite/WebRoot.gd
Normal file
18
web/users_sqlite/WebRoot.gd
Normal file
@ -0,0 +1,18 @@
|
||||
extends WebRoot
|
||||
|
||||
export(String, MULTILINE) var menu_str : String
|
||||
|
||||
func _render_main_menu(request: WebServerRequest) -> void:
|
||||
# You can render the menu differently for logged in users for example
|
||||
# The middlewares will run before routing (in order they are in the middlewares property)
|
||||
request.body += menu_str
|
||||
|
||||
# The UserSessionSetupWebServerMiddleware makes this available here:
|
||||
# If you want to do this manually, you can do it via request.session + the UserDB singleton
|
||||
# I recommend looking at the middleware code on the engine c++ side to see an example
|
||||
var user : User = request.get_meta("user")
|
||||
|
||||
if user:
|
||||
request.body += "You are logged in as : " + user.user_name + ".<br><br>"
|
||||
else:
|
||||
request.body += "You are not logged in.<br><br>"
|
16
web/users_sqlite/WebServerSimple.gd
Normal file
16
web/users_sqlite/WebServerSimple.gd
Normal file
@ -0,0 +1,16 @@
|
||||
extends WebServerSimple
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a: int = 2
|
||||
# var b: String = "text"
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
start()
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta: float) -> void:
|
||||
# pass
|
7
web/users_sqlite/default_env.tres
Normal file
7
web/users_sqlite/default_env.tres
Normal file
@ -0,0 +1,7 @@
|
||||
[gd_resource type="Environment3D" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
BIN
web/users_sqlite/icon.png
Normal file
BIN
web/users_sqlite/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
35
web/users_sqlite/icon.png.import
Normal file
35
web/users_sqlite/icon.png.import
Normal file
@ -0,0 +1,35 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.png"
|
||||
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
process/normal_map_invert_y=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
25
web/users_sqlite/project.pandemonium
Normal file
25
web/users_sqlite/project.pandemonium
Normal file
@ -0,0 +1,25 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=4
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Users Static"
|
||||
run/main_scene="res://Main.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[physics]
|
||||
|
||||
common/enable_pause_aware_picking=true
|
||||
|
||||
[rendering]
|
||||
|
||||
vram_compression/import_etc=true
|
||||
vram_compression/import_etc2=false
|
||||
environment/default_environment="res://default_env.tres"
|
Loading…
Reference in New Issue
Block a user