diff --git a/.gitignore b/.gitignore index ad3605a..cde8139 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .aider* golias +store.json diff --git a/components/index.html b/components/index.html index a2f395b..9da0975 100644 --- a/components/index.html +++ b/components/index.html @@ -8,6 +8,8 @@ +
+ {{template "login"}}

Word Color Cards

{{range $word, $color := .}} @@ -19,12 +21,13 @@ min-width: 100px; text-align: center; color: white; - text-shadow: 0 2px 4px rgba(0,0,0,0.5); + text-shadow: 0 2px 4px rgba(0,0,0,0.8); "> {{$word}}
{{end}}
+ {{end}} diff --git a/components/login.html b/components/login.html new file mode 100644 index 0000000..bbbe3a4 --- /dev/null +++ b/components/login.html @@ -0,0 +1,16 @@ +{{define "login"}} +
+
+
+ +
+ +
+
this name looks available
+
+
+ +
+
+
+{{end}} diff --git a/handlers/auth.go b/handlers/auth.go index a3b877a..62d9c2e 100644 --- a/handlers/auth.go +++ b/handlers/auth.go @@ -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 diff --git a/handlers/middleware.go b/handlers/middleware.go index b655f51..11b8df5 100644 --- a/handlers/middleware.go +++ b/handlers/middleware.go @@ -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(), ) diff --git a/main.go b/main.go index 58ca94c..5f104e0 100644 --- a/main.go +++ b/main.go @@ -2,16 +2,16 @@ package main import ( "fmt" - "net/http" "golias/handlers" + "net/http" "time" ) // TODO: add config as param -func ListenToRequests(port string) error{ +func ListenToRequests(port string) error { mux := http.NewServeMux() server := &http.Server{ - Handler: mux, + Handler: handlers.LogRequests(handlers.GetSession(mux)), Addr: port, ReadTimeout: time.Second * 5, WriteTimeout: time.Second * 5,