From e8193e627aa1efa62bdae59b77238641ae071f61 Mon Sep 17 00:00:00 2001 From: bel Date: Sat, 17 Jun 2023 09:08:20 -0600 Subject: [PATCH] handles --- vicuna-tools.d/main.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/vicuna-tools.d/main.go b/vicuna-tools.d/main.go index cd6599d..e0abe3a 100644 --- a/vicuna-tools.d/main.go +++ b/vicuna-tools.d/main.go @@ -105,13 +105,28 @@ func handle(w http.ResponseWriter, r *http.Request) { } func _handle(w http.ResponseWriter, r *http.Request) error { - u, p, ok := r.BasicAuth() - if !ok { - w.Header().Set("WWW-Authenticate", "Basic") - w.WriteHeader(http.StatusUnauthorized) - return errors.New("no auth") + switch r.URL.Path { + case "/login": + return handleLogin(w, r) + case "/": + return handleUI(w, r) + default: + http.NotFound(w, r) + return nil } - _, _ = u, p +} + +func handleLogin(w http.ResponseWriter, r *http.Request) error { + return errors.New("not impl") +} + +func handleUI(w http.ResponseWriter, r *http.Request) error { + cookie, err := ParseCookie(r) + if err != nil { + http.Redirect(w, r, "/login", http.StatusTemporaryRedirect) + return err + } + _ = cookie Config.Semaphore.Lock() defer Config.Semaphore.Unlock()