mirror of
https://github.com/kaaninchen/Laterna.git
synced 2026-09-17 19:12:48 +00:00
authentification groundworks
This commit is contained in:
@@ -2,6 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"flag"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/siestaw/laterna/server/cmd/internal/logger"
|
||||
@@ -18,10 +19,18 @@ func ConnectDB() {
|
||||
}
|
||||
logger.DBLogger.Printf("Successfully connected to the database!")
|
||||
InitDB()
|
||||
|
||||
resetAdmin := flag.Bool("resetAdminToken", false, "recreate the admin token")
|
||||
flag.Parse()
|
||||
|
||||
if *resetAdmin {
|
||||
ResetAdmin()
|
||||
}
|
||||
}
|
||||
|
||||
func InitDB() {
|
||||
_, err := DB.Exec(`
|
||||
// Legacy purposes, DELETE
|
||||
_, err := DB.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS lamp_state (
|
||||
id TEXT PRIMARY KEY,
|
||||
color TEXT NOT NULL,
|
||||
@@ -32,4 +41,24 @@ func InitDB() {
|
||||
if err != nil {
|
||||
logger.DBLogger.Fatalf("An error occured while initializing the database: %v", err)
|
||||
}
|
||||
|
||||
_, err = DB.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS controllers (
|
||||
id INTEGER PRIMARY KEY,
|
||||
token_hash TEXT NOT NULL,
|
||||
color TEXT,
|
||||
updated_at DATETIME
|
||||
);`)
|
||||
if err != nil {
|
||||
logger.DBLogger.Fatalf("An error occured while initializing the database: %v", err)
|
||||
}
|
||||
|
||||
_, err = DB.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS permissions (
|
||||
controller_id INTEGER,
|
||||
target_id INTEGER
|
||||
);`)
|
||||
if err != nil {
|
||||
logger.DBLogger.Fatalf("An error occured while initializing the database: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user