fuckass db shit
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
module database
|
module database
|
||||||
|
|
||||||
import fleximus.argon2
|
|
||||||
import rand
|
import rand
|
||||||
|
// import db.mysql
|
||||||
|
import db.redis
|
||||||
|
import fleximus.argon2
|
||||||
|
|
||||||
pub struct Crypto {}
|
pub struct Crypto {}
|
||||||
|
|
||||||
@@ -15,24 +17,42 @@ pub fn Crypto.hash_verify(password string, hash string) !bool {
|
|||||||
return argon2.verify(hash, password.bytes()) or { return error('argon2 verify failed: ${err}') }
|
return argon2.verify(hash, password.bytes()) or { return error('argon2 verify failed: ${err}') }
|
||||||
}
|
}
|
||||||
|
|
||||||
// db structure
|
// struct Database {
|
||||||
|
// mut:
|
||||||
|
// conn mysql.DB
|
||||||
|
// }
|
||||||
//
|
//
|
||||||
// users
|
// pub fn get_connection(cfg util.Config) !&Database {
|
||||||
// CREATE TABLE users (
|
// // connection := mysql.connect(mysql.Config{
|
||||||
// id SERIAL PRIMARY KEY,
|
// // host: cfg.database.host
|
||||||
// name TEXT UNIQUE NOT NULL,
|
// // // port: u32(cfg.database.port)
|
||||||
// password_hash TEXT NOT NULL
|
// // dbname: 'CDN_DATABASE'
|
||||||
// );
|
// // username: cfg.database.username
|
||||||
|
// // password: cfg.database.password
|
||||||
|
// // })!
|
||||||
//
|
//
|
||||||
// logins
|
// //return &Database{ conn: connection }
|
||||||
// CREATE TABLE login_attempts (
|
// return &Database{}
|
||||||
// id SERIAL PRIMARY KEY,
|
// }
|
||||||
// username TEXT NOT NULL,
|
|
||||||
// ip TEXT NOT NULL,
|
|
||||||
// success BOOLEAN NOT NULL,
|
|
||||||
// attempt_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// files
|
|
||||||
//
|
//
|
||||||
|
// pub fn (mut db Database) query[T](query_fn fn(conn &mysql.Connection) ![]T) ![]T {
|
||||||
|
// result := query_fn(db.conn) or {
|
||||||
|
// // Connection died, reconnect
|
||||||
|
// db.conn = mysql.connect(db.config)!
|
||||||
|
// return query_fn(db.conn)!
|
||||||
|
// }
|
||||||
|
// return result
|
||||||
|
// }
|
||||||
//
|
//
|
||||||
|
// pub fn Database.test() {}
|
||||||
|
|
||||||
|
pub fn test() ! {
|
||||||
|
mut r := redis.connect(redis.Config{
|
||||||
|
host: 'vpn.security-command.org'
|
||||||
|
port: 6767
|
||||||
|
password: 'SuperSecretPassword123'
|
||||||
|
})!
|
||||||
|
|
||||||
|
pong := r.ping() or { panic(err) }
|
||||||
|
println(pong)
|
||||||
|
}
|
||||||
|
|||||||
22
app/src/database/tables.v
Normal file
22
app/src/database/tables.v
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
module database
|
||||||
|
|
||||||
|
@[table: 'users']
|
||||||
|
struct Users {
|
||||||
|
id int @[primary; serial]
|
||||||
|
name string @[nonnull; unique]
|
||||||
|
password_hash string @[nonnull]
|
||||||
|
}
|
||||||
|
|
||||||
|
@[table: 'login_attempts']
|
||||||
|
struct Logins {
|
||||||
|
ip string @[primary]
|
||||||
|
attempts int @[nonnull]
|
||||||
|
attempt_time string @[default: 'CURRENT_TIMESTAMP'; nonnull]
|
||||||
|
}
|
||||||
|
|
||||||
|
@[table: 'files']
|
||||||
|
struct Files {
|
||||||
|
id int @[primary; serial]
|
||||||
|
path string @[nonnull; unique]
|
||||||
|
visible bool @[default: false; nonnull]
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ module main
|
|||||||
import os
|
import os
|
||||||
import veb
|
import veb
|
||||||
import util
|
import util
|
||||||
|
import database
|
||||||
import thomaspeissl.dotenv
|
import thomaspeissl.dotenv
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -142,6 +143,10 @@ fn main() {
|
|||||||
app: &app
|
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)!
|
||||||
|
|
||||||
app.enable_static_compression = true
|
app.enable_static_compression = true
|
||||||
|
|||||||
Reference in New Issue
Block a user