From ff2230e2f7ef1cc6d737bcd62e8fb2a7c8ada19c Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Fri, 31 Jul 2026 13:06:23 -0700 Subject: [PATCH] auth request handler --- main/main.go | 12 ++++++------ webserver/login_page.go | 11 +++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/main/main.go b/main/main.go index 19b354a..0a6bb7e 100644 --- a/main/main.go +++ b/main/main.go @@ -1,15 +1,14 @@ package main import ( - "net/http" + "fmt" "astraltech.xyz/calendar/v2/webserver" ) -func LoginHandler(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/html; charset=utf-8") - var test_html string = "Hello, world" - w.Write([]byte(test_html)) +func HandleAuthRequest(username string, password string) bool { + fmt.Printf("Handling Auth request for %s", username) + return false } func main() { @@ -17,7 +16,8 @@ func main() { init_dav_client() webserver.ServeLoginPage("/login", webserver.CustomizableLoginData{ - ServiceName: "Astral Calendar", + ServiceName: "Astral Calendar", + AuthRequestFunction: HandleAuthRequest, }) webserver.EnableLogoRoute() webserver.EnableStaticRoute() diff --git a/webserver/login_page.go b/webserver/login_page.go index 25b331d..94d0d6c 100644 --- a/webserver/login_page.go +++ b/webserver/login_page.go @@ -12,7 +12,8 @@ type LoginPageData struct { } type CustomizableLoginData struct { - ServiceName string + ServiceName string + AuthRequestFunction func(string, string) bool } var LoginPageDataCustomizations CustomizableLoginData @@ -28,7 +29,13 @@ func loginHandler(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodPost { username := r.FormValue("username") if strings.Contains(username, "/") { - tmpl.Execute(w, LoginPageData{IsHiddenClassList: ""}) + tmpl.Execute(w, LoginPageData{IsHiddenClassList: "", LoginData: LoginPageDataCustomizations}) + } + password := r.FormValue("password") + + auth_success := LoginPageDataCustomizations.AuthRequestFunction(username, password) + if auth_success == false { + tmpl.Execute(w, LoginPageData{IsHiddenClassList: "", LoginData: LoginPageDataCustomizations}) } } }