Finally get login working.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user