Feat: better logs; login page

This commit is contained in:
Grail Finder
2025-05-02 10:54:51 +03:00
parent 043026de75
commit d18855cd49
6 changed files with 31 additions and 16 deletions

View File

@ -8,7 +8,6 @@ import (
"golias/models"
"golias/utils"
"html/template"
"log/slog"
"net/http"
"strings"
"time"
@ -24,7 +23,7 @@ func HandleFrontLogin(w http.ResponseWriter, r *http.Request) {
username := r.PostFormValue("username")
if username == "" {
msg := "username not provided"
slog.Error(msg)
log.Error(msg)
abortWithError(w, msg)
return
}
@ -34,7 +33,7 @@ func HandleFrontLogin(w http.ResponseWriter, r *http.Request) {
// login user
cookie, err := makeCookie(cleanName, r.RemoteAddr)
if err != nil {
slog.Error("failed to login", "error", err)
log.Error("failed to login", "error", err)
abortWithError(w, err.Error())
return
}
@ -75,13 +74,13 @@ func makeCookie(username string, remote string) (*http.Cookie, error) {
SameSite: http.SameSiteNoneMode,
Domain: cfg.ServerConfig.Host,
}
slog.Info("check remote addr for cookie set",
log.Info("check remote addr for cookie set",
"remote", remote, "session", session)
if strings.Contains(remote, "192.168.0") {
// no idea what is going on
// cookie.Domain = "192.168.0.15"
cookie.Domain = "home.host"
slog.Info("changing cookie domain", "domain", cookie.Domain)
log.Info("changing cookie domain", "domain", cookie.Domain)
}
// set ctx?
// set user in session

View File

@ -32,17 +32,13 @@ func (w *responseWriterWrapper) WriteHeader(status int) {
func LogRequests(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
log.Info("request started", "method", r.Method, "path", r.URL.Path)
// Wrap response writer to capture status code
ww := &responseWriterWrapper{ResponseWriter: w}
next.ServeHTTP(ww, r)
duration := time.Since(start)
log.Debug("request completed",
"method", r.Method,
"path", r.URL.Path,
log.Debug("request completed",
"method", r.Method,
"path", r.URL.Path,
"status", ww.status,
"duration", duration.String(),
)