working, beta

This commit is contained in:
2025-11-26 13:22:39 +00:00
parent 635f16f8ff
commit 330a22068f

View File

@@ -3,10 +3,9 @@ module main
import os
import veb
import util
import database
import thomaspeissl.dotenv
//
// structs
pub struct User {
pub mut:
@@ -88,9 +87,14 @@ fn (mut ctx Context) error_page(code int, short string, long string) string {
return $tmpl('template/error.html')
}
pub fn (mut ctx Context) request_error(msg string) veb.Result {
ctx.res.set_status(.bad_request)
return ctx.html(ctx.error_page(400, 'Bad Request', 'This request is malformed or otherwise invalid.'))
}
pub fn (mut ctx Context) forbidden() veb.Result {
ctx.res.set_status(.forbidden)
return ctx.html(ctx.error_page(403, 'Forbidden', "Oops! You aren't allowed around here."))
return ctx.html(ctx.error_page(403, 'Forbidden', 'Oops! You aren't allowed around here.'))
}
pub fn (mut ctx Context) not_found() veb.Result {
@@ -98,15 +102,20 @@ pub fn (mut ctx Context) not_found() veb.Result {
return ctx.html(ctx.error_page(404, 'Not found', 'Oops! The page you are looking for does not exist.'))
}
// --
pub fn (mut ctx Context) server_error(msg string) veb.Result {
ctx.res.set_status(.internal_server_error)
return ctx.html(ctx.error_page(500, 'Interal Server Error', 'Oops! Something went wrong here.'))
}
fn populate() (&util.Config, &util.Embedded) {
// main
fn populate() (&util.Config, &util.Embedded)
{
dotenv.load()
dotenv.require('CDN_DB_HOST', 'CDN_DB_PORT')
def_root := $d('root', '.')
def_port := int($d('port', 6767))
def_user := $d('username', 'cdn')
def_pass := $d('password', 'totallySafeCdnDatabasePassword1235')
@@ -116,16 +125,8 @@ fn populate() (&util.Config, &util.Embedded) {
database: &util.Database{
host: os.getenv('CDN_DB_HOST').str()
port: os.getenv('CDN_DB_PORT').int()
username: if os.getenv('CDN_DB_USERNAME') != '' {
os.getenv('CDN_DB_USERNAME').str()
} else {
def_user
}
password: if os.getenv('CDN_DB_PASSWORD') != '' {
os.getenv('CDN_DB_PASSWORD').str()
} else {
def_pass
}
username: if os.getenv('CDN_DB_USERNAME') != '' { os.getenv('CDN_DB_USERNAME').str() } else { def_user }
password: if os.getenv('CDN_DB_PASSWORD') != '' { os.getenv('CDN_DB_PASSWORD').str() } else { def_pass }
}
}, &util.Embedded{
style_css: $embed_file('template/assets/style.css', .zlib).to_string()
@@ -133,26 +134,18 @@ fn populate() (&util.Config, &util.Embedded) {
}
}
fn main() {
fn main()
{
cfg, mut embed := populate()
mut app := &App{
cfg: cfg
embed: embed
}
mut auth := &Auth{
app: &app
}
database.test()!
// db := database.get_connection(app.cfg)!
mut app := &App{ cfg: cfg, embed: embed }
mut auth := &Auth{ app: &app }
app.register_controller[Auth, Context]('/auth', mut auth)!
app.enable_static_compression = true
app.use(veb.encode_auto[Context]())
app.use(veb.MiddlewareOptions[Context]{
app.use(veb.MiddlewareOptions[Context] {
handler: fn [mut embed] (mut ctx Context) bool {
ctx.embed = embed
return true