feat: a lot

i did a lot of work, and i also forgot to add commits regularly. I added the controller routes to create and delete controllers, improved error handling und improved the authentification process. I'm gonna add an websocket next and then I should be hopefully done with the foundations of this project. I may also add anviewControllers route which respons with every available controller
This commit is contained in:
Siesta
2025-07-20 18:31:38 +02:00
parent 25bd0cc0c8
commit 57592b4987
10 changed files with 138 additions and 63 deletions
+22 -6
View File
@@ -9,15 +9,31 @@ import (
"golang.org/x/crypto/bcrypt"
)
func CreateController(id int) string {
token, _ := utils.GenerateToken()
hash, _ := utils.HashToken(token)
_, err := DB.Exec("INSERT INTO controllers (id, token_hash) VALUES (?, ?)", id, hash)
func CreateController() (int64, error) {
result, err := DB.Exec("INSERT INTO controllers (color, updated_at) VALUES (?, CURRENT_TIMESTAMP)", "#FFFFF")
if err != nil {
logger.DBLogger.Fatalf("Error creating controller with ID %v: %s",id, err)
logger.DBLogger.Printf("Error creating controller: %v", err)
return 0, err
}
id, err := result.LastInsertId()
if err != nil {
logger.DBLogger.Printf("Error fetching controller ID: %v", err)
return 0, err
}
return id, nil
}
func CreateAdmin() string {
token, err := utils.GenerateToken()
if err != nil {
logger.DBLogger.Fatalf("Error generating admin token: %v", err)
}
token_hash, err := utils.HashToken(token)
if err != nil {
logger.DBLogger.Fatalf("Error hashing admin token: %v", err)
}
DB.Exec("INSERT INTO controllers (id, token_hash) VALUES (0, ?)", token_hash)
return token
}