fuckass db shit
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
module database
|
||||
|
||||
import fleximus.argon2
|
||||
import rand
|
||||
// import db.mysql
|
||||
import db.redis
|
||||
import fleximus.argon2
|
||||
|
||||
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}') }
|
||||
}
|
||||
|
||||
// db structure
|
||||
// struct Database {
|
||||
// mut:
|
||||
// conn mysql.DB
|
||||
// }
|
||||
//
|
||||
// users
|
||||
// CREATE TABLE users (
|
||||
// id SERIAL PRIMARY KEY,
|
||||
// name TEXT UNIQUE NOT NULL,
|
||||
// password_hash TEXT NOT NULL
|
||||
// );
|
||||
// pub fn get_connection(cfg util.Config) !&Database {
|
||||
// // connection := mysql.connect(mysql.Config{
|
||||
// // host: cfg.database.host
|
||||
// // // port: u32(cfg.database.port)
|
||||
// // dbname: 'CDN_DATABASE'
|
||||
// // username: cfg.database.username
|
||||
// // password: cfg.database.password
|
||||
// // })!
|
||||
//
|
||||
// logins
|
||||
// CREATE TABLE login_attempts (
|
||||
// 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
|
||||
// //return &Database{ conn: connection }
|
||||
// return &Database{}
|
||||
// }
|
||||
//
|
||||
// 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 veb
|
||||
import util
|
||||
import database
|
||||
import thomaspeissl.dotenv
|
||||
|
||||
//
|
||||
@@ -142,6 +143,10 @@ fn main() {
|
||||
app: &app
|
||||
}
|
||||
|
||||
database.test()!
|
||||
|
||||
// db := database.get_connection(app.cfg)!
|
||||
|
||||
app.register_controller[Auth, Context]('/auth', mut auth)!
|
||||
|
||||
app.enable_static_compression = true
|
||||
|
||||
Reference in New Issue
Block a user