working, beta
This commit is contained in:
@@ -3,10 +3,9 @@ module main
|
|||||||
import os
|
import os
|
||||||
import veb
|
import veb
|
||||||
import util
|
import util
|
||||||
import database
|
|
||||||
import thomaspeissl.dotenv
|
import thomaspeissl.dotenv
|
||||||
|
|
||||||
//
|
// structs
|
||||||
|
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub mut:
|
pub mut:
|
||||||
@@ -88,9 +87,14 @@ fn (mut ctx Context) error_page(code int, short string, long string) string {
|
|||||||
return $tmpl('template/error.html')
|
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 {
|
pub fn (mut ctx Context) forbidden() veb.Result {
|
||||||
ctx.res.set_status(.forbidden)
|
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 {
|
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.'))
|
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.load()
|
||||||
dotenv.require('CDN_DB_HOST', 'CDN_DB_PORT')
|
dotenv.require('CDN_DB_HOST', 'CDN_DB_PORT')
|
||||||
|
|
||||||
def_root := $d('root', '.')
|
def_root := $d('root', '.')
|
||||||
def_port := int($d('port', 6767))
|
def_port := int($d('port', 6767))
|
||||||
|
|
||||||
def_user := $d('username', 'cdn')
|
def_user := $d('username', 'cdn')
|
||||||
def_pass := $d('password', 'totallySafeCdnDatabasePassword1235')
|
def_pass := $d('password', 'totallySafeCdnDatabasePassword1235')
|
||||||
|
|
||||||
@@ -116,16 +125,8 @@ fn populate() (&util.Config, &util.Embedded) {
|
|||||||
database: &util.Database{
|
database: &util.Database{
|
||||||
host: os.getenv('CDN_DB_HOST').str()
|
host: os.getenv('CDN_DB_HOST').str()
|
||||||
port: os.getenv('CDN_DB_PORT').int()
|
port: os.getenv('CDN_DB_PORT').int()
|
||||||
username: if os.getenv('CDN_DB_USERNAME') != '' {
|
username: if os.getenv('CDN_DB_USERNAME') != '' { os.getenv('CDN_DB_USERNAME').str() } else { def_user }
|
||||||
os.getenv('CDN_DB_USERNAME').str()
|
password: if os.getenv('CDN_DB_PASSWORD') != '' { os.getenv('CDN_DB_PASSWORD').str() } else { def_pass }
|
||||||
} else {
|
|
||||||
def_user
|
|
||||||
}
|
|
||||||
password: if os.getenv('CDN_DB_PASSWORD') != '' {
|
|
||||||
os.getenv('CDN_DB_PASSWORD').str()
|
|
||||||
} else {
|
|
||||||
def_pass
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, &util.Embedded{
|
}, &util.Embedded{
|
||||||
style_css: $embed_file('template/assets/style.css', .zlib).to_string()
|
style_css: $embed_file('template/assets/style.css', .zlib).to_string()
|
||||||
@@ -133,19 +134,11 @@ fn populate() (&util.Config, &util.Embedded) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main()
|
||||||
|
{
|
||||||
cfg, mut embed := populate()
|
cfg, mut embed := populate()
|
||||||
mut app := &App{
|
mut app := &App{ cfg: cfg, embed: embed }
|
||||||
cfg: cfg
|
mut auth := &Auth{ app: &app }
|
||||||
embed: embed
|
|
||||||
}
|
|
||||||
mut auth := &Auth{
|
|
||||||
app: &app
|
|
||||||
}
|
|
||||||
|
|
||||||
database.test()!
|
|
||||||
|
|
||||||
// db := database.get_connection(app.cfg)!
|
|
||||||
|
|
||||||
app.register_controller[Auth, Context]('/auth', mut auth)!
|
app.register_controller[Auth, Context]('/auth', mut auth)!
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user