package api import ( "net/http" ) const templatesDir = "internal/ui/templates" // hasSession reports whether the request carries a valid, non-expired session cookie. func (a *API) hasSession(r *http.Request) bool { c, err := r.Cookie(sessionCookieName) if err != nil { return false } _, ok := a.sessions.Get(c.Value) return ok } func (a *API) handleDashboard(w http.ResponseWriter, r *http.Request) { if !a.hasSession(r) { http.Redirect(w, r, "/login", http.StatusFound) return } http.ServeFile(w, r, templatesDir+"/dashboard.html") } func (a *API) handleLoginPage(w http.ResponseWriter, r *http.Request) { if a.hasSession(r) { http.Redirect(w, r, "/", http.StatusFound) return } http.ServeFile(w, r, templatesDir+"/login.html") } func (a *API) handleServerPage(w http.ResponseWriter, r *http.Request) { if !a.hasSession(r) { http.Redirect(w, r, "/login", http.StatusFound) return } http.ServeFile(w, r, templatesDir+"/server.html") }