Massive refactor!
This commit is contained in:
@@ -59,35 +59,3 @@ func GetUserByUsername(username string) *User {
|
||||
|
||||
return &user
|
||||
}
|
||||
|
||||
func GetUserByID(id int) *User {
|
||||
row := db.QueryRow("SELECT id, username, password_hash, is_admin FROM users WHERE id = ?", id)
|
||||
|
||||
var user User
|
||||
err := row.Scan(&user.Id, &user.Username, &user.PasswordHash, &user.IsAdmin)
|
||||
if err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
log.Println("DB error:", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return &user
|
||||
}
|
||||
|
||||
func LogLoginAttempt(username string, success bool) {
|
||||
_, err := db.Exec("INSERT INTO auditlog (username, success, timestamp) VALUES (?, ?, ?)",
|
||||
username, boolToInt(success), time.Now().Format(time.RFC3339)) // tOdO: SHOULD BE USING UTC
|
||||
if err != nil {
|
||||
log.Println("❌ Failed to log login:", err)
|
||||
}
|
||||
} // ToDo this shouldn't be in models. Also why did i build a bool to int? just use the bool
|
||||
|
||||
func boolToInt(b bool) int {
|
||||
if b {
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user