Finally get login working.

This commit is contained in:
2025-03-26 08:36:11 +00:00
parent e55508661c
commit e3f3d73fdd
6 changed files with 96 additions and 28 deletions

View File

@@ -3,6 +3,7 @@ package models
import (
"database/sql"
"log"
"time"
)
type User struct {
@@ -47,5 +48,21 @@ func GetUserByID(id int) *User {
}
return nil
}
log.Printf("📦 Looking up user ID %d", id)
return &user
}
func LogLoginAttempt(username string, success bool) {
_, err := db.Exec("INSERT INTO login_audit (username, success, timestamp) VALUES (?, ?, ?)",
username, boolToInt(success), time.Now().Format(time.RFC3339))
if err != nil {
log.Println("❌ Failed to log login:", err)
}
}
func boolToInt(b bool) int {
if b {
return 1
}
return 0
}